Google图表 - 自定义列标签分组

时间:2014-09-16 02:57:51

标签: javascript php google-visualization

是否可以在Google图表中自定义列标签?比如将类似数据分组到一个标签

google.load('visualization', '1', {
  packages: ['table']
});

function drawVisualization() {
  var data = new google.visualization.DataTable();
  data.addColumn('string', 'Month'); // Implicit domain label col.
  data.addColumn('number', 'Value'); // Implicit series 1 data col.
  data.addColumn({
    type: 'string',
    role: 'tooltip'
  }); // annotation role col.
  data.addColumn({
    type: 'string',
    role: 'domain'
  }); // annotation role col.
  data.addRows([
    ["March", 26075, "17 - Mar - 2014 | 26075", "March"],
    ["", 26150, "18 - Mar - 2014 | 26150", "March"],
    ["", 25400, "28 - Mar - 2014 | 25400", "March"],
    ["April", 26000, "01 - Apr - 2014 | 26000", "April"],
    ["", 28300, "28 - Apr - 2014 | 28300", "April"],
    ["", 28500, "29 - Apr - 2014 | 28500", "April"],
    ["", 29000, "30 - Apr - 2014 | 29000", "April"],
    ["May", 29400, "02 - May - 2014 | 29400", "May"],
    ["", 27800, "30 - May - 2014 | 27800", "May"],
    ["June", 27325, "02 - Jun - 2014 | 27325", "June"],
    ["", 27150, "19 - Jun - 2014 | 27150", "June"],
    ["", 29000, "26 - Jun - 2014 | 29000", "June"],
    ["", 29300, "27 - Jun - 2014 | 29300", "June"],
    ["", 28700, "30 - Jun - 2014 | 28700", "June"],
    ["July", 28175, "01 - Jul - 2014 | 28175", "July"],
    ["", 26150, "21 - Jul - 2014 | 26150", "July"],
    ["", 26000, "24 - Jul - 2014 | 26000", "July"],
    ["", 26575, "25 - Jul - 2014 | 26575", "July"],
    ["August", 26700, "04 - Aug - 2014 | 26700", "August"],
    ["", 25900, "26 - Aug - 2014 | 25900", "August"],
    ["", 25850, "27 - Aug - 2014 | 25850", "August"],
    ["", 25900, "28 - Aug - 2014 | 25900", "August"],
    ["", 26000, "29 - Aug - 2014 | 26000", "August"],
    ["September", 25500, "01 - Sep - 2014 | 25500", "September"],
    ["", 25800, "08 - Sep - 2014 | 25800", "September"],
    ["", 25775, "09 - Sep - 2014 | 25775", "September"],
  ]);
  // Create and draw the visualization.
  visualization = new google.visualization.Table(document.getElementById('table'));
  visualization.draw(data, {});
}
google.setOnLoadCallback(drawVisualization);
<script src="https://www.google.com/jsapi"></script>
<div id="table"></div>

我删除了大量数据,但我希望数据按月分组,而图表只显示月份名称作为列。

有什么建议吗?

0 个答案:

没有答案