带有多个条形和线条的Google组合图表

时间:2016-06-24 15:29:44

标签: charts google-visualization

查看此图片我正在显示一些数据,我需要将每个条形图与线图所示的数据进行比较:

google combo chart bar + line graph

这可以在Google组合图表中使用吗?

2 个答案:

答案 0 :(得分:3)

确定有可能,请参阅以下示例...

google.charts.load('current', {
  callback: function () {
    var data = google.visualization.arrayToDataTable([
      ['Month', 'Bolivia', 'Ecuador', 'Madagascar', 'Papua New Guinea', 'Rwanda', 'Average'],
      ['2004/05',  165,      938,         522,             998,           450,      614.6],
      ['2005/06',  135,      1120,        599,             1268,          288,      682],
      ['2006/07',  157,      1167,        587,             807,           397,      623],
      ['2007/08',  139,      1110,        615,             968,           215,      609.4],
      ['2008/09',  136,      691,         629,             1026,          366,      569.6]
    ]);

    var chart = new google.visualization.ComboChart(document.getElementById('chart_div'));
    chart.draw(data, {
      title : 'Monthly Coffee Production by Country',
      vAxis: {title: 'Cups'},
      hAxis: {title: 'Month'},
      height: 420,
      orientation: 'vertical',
      seriesType: 'bars',
      series: {
        5: {
          pointSize: 5,
          type: 'line'
        }
      }
    });
  },
  packages: ['corechart']
});
<script src="https://www.gstatic.com/charts/loader.js"></script>
<div id="chart_div"></div>

答案 1 :(得分:0)

Google Charts API提供了一个javascript包装器,允许您自定义组合图表。它有很多配置选项,您可以在这里查看Google Combo Chart Config options。您可以使用注释选项在条形图上构建线条。有关完整的组合图表文档,请访问此处https://developers.google.com/chart/interactive/docs/gallery/combochart