谷歌图表在图表顶部显示名称

时间:2018-02-22 12:39:01

标签: javascript google-visualization

我正在使用柱形图显示数据。

我想在每列的顶部显示列的名称。

我的阵列喜欢这样:

0: (3) ["Date", "United State", "Australia"] 
1: (3) ["Week 48", 66, 67]
2: (3) ["Week 02", 66, 0]

我尝试添加{role:' annotation'在我的标题中但没有结果。

我想要这样的东西。我不知道我可以从哪里开始,任何提示或帮助。

enter image description here

1 个答案:

答案 0 :(得分:0)

注释列应该跟随需要注释的每个系列列

数组的结构应如下......

["Date", "United States", {role: 'annotation'}, "Australia", {role: 'annotation'}],
["Week 48", 66, "United States", 67, "Australia"],
["Week 02", 66, "United States", 0, "Australia"]

请参阅以下工作代码段...



google.charts.load('current', {
  packages: ['corechart']
}).then(function () {
  var dataTable = google.visualization.arrayToDataTable([
    ["Date", "United States", {type: 'string', role: 'annotation'}, "Australia", {type: 'string', role: 'annotation'}],
    ["Week 48", 66, "United States", 67, "Australia"],
    ["Week 02", 66, "United States", 0, "Australia"]
  ]);
  var chart = new google.visualization.ColumnChart(document.getElementById('chart_div'));
  chart.draw(dataTable);
});

<script src="https://www.gstatic.com/charts/loader.js"></script>
<div id="chart_div"></div>
&#13;
&#13;
&#13;