简体   繁体   English

如何从谷歌图表中删除标题和公告

[英]How to remove title and bulletins from google charts

I'm using google donut chart, but it's showing the title and bullets.我正在使用谷歌甜甜圈图,但它显示了标题和项目符号。

I need to know how to remove them and make the chart fit inside the card.我需要知道如何移除它们并使图表适合卡内。

<div class="col-xl-4 col-lg-12 col-md-4 col-sm-12 col-12">
    <div class="card">
        <h5 class="card-header">Credits History</h5>
        <div class="card-body">
            <script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script>
            <script type="text/javascript">
              google.charts.load("current", {packages:["corechart"]});
              google.charts.setOnLoadCallback(drawChart);
              function drawChart() {
                var data = google.visualization.arrayToDataTable([
                  ['Task', 'Hours per Day'],
                  ['Work',     11],
                  ['Eat',      2]
                ]);

                var options = {
                  title: 'My Daily Activities',
                  pieHole: 0.4,
                };

                var chart = new google.visualization.PieChart(document.getElementById('donutchart'));
                chart.draw(data, options);
              }
            </script>  
            <div id="donutchart" style="width: 220px; height: 155px;"></div>
        </div>
    </div>
</div>

to remove the chart title, remove the title option from the chart options.要删除图表标题,请从图表选项中删除title选项。

as for the bullets, or bulletins, that is the chart's legend,至于子弹,或公告,那是图表的图例,
to remove, add the following option --> legend: 'none'要删除,请添加以下选项 --> legend: 'none'

and you can use the chartArea option to maximize the chart within the container.并且您可以使用chartArea选项来最大化容器内的图表。

var options = {
  chartArea: {
    height: '100%',
    width: '100%'
  },
  legend: 'none',
  pieHole: 0.4
};

see following working snippet...请参阅以下工作片段...

 google.charts.load("current", { packages: ["corechart"] }); google.charts.setOnLoadCallback(drawChart); function drawChart() { var data = google.visualization.arrayToDataTable([ ['Task', 'Hours per Day'], ['Work', 11], ['Eat', 2] ]); var options = { chartArea: { height: '100%', width: '100%' }, legend: 'none', pieHole: 0.4 }; var chart = new google.visualization.PieChart(document.getElementById('donutchart')); chart.draw(data, options); }
 <script src="https://www.gstatic.com/charts/loader.js"></script> <div id="donutchart" style="width: 220px; height: 155px;"></div>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM