Google 图表图例自定义

Google charts legend customize

我有两个 series/columns fileSizeoutput Target.

有没有可能两个在图例中只显示output Target而隐藏fileSize

您可以使用 visibleInLegend configuration option

只分配给系列号

请参阅以下工作片段...

google.charts.load('current', {
  callback: function () {
    var data = google.visualization.arrayToDataTable([
      ['File', 'fileSize', 'output Target'],
      ['a', 10, 15],
      ['b', 12, 18],
      ['c', 14, 21],
      ['d', 16, 24]
    ]);

    var container = document.getElementById('chart_div');
    var chart = new google.visualization.ColumnChart(container);

    chart.draw(data, {
      legend: {
        position: 'bottom'
      },
      series: {
        0: {
          visibleInLegend: false
        }
      }
    });
  },
  packages: ['corechart']
});
<script src="https://www.gstatic.com/charts/loader.js"></script>
<div id="chart_div"></div>