堆积条形图-->堆积柱形图

Stacked Bar Chart --> Stacked Column Chart

本文关键字:柱形图 gt 条形图      更新时间:2023-09-26

我正在尝试将此常规条形图转换为堆叠柱形图。我一直在玩JSfiddle有一段时间了,就是拿不到它。

我认为我的问题很小,但我就是无法确定。任何帮助都将不胜感激。谢谢

  <script type="text/javascript" src="https://www.google.com/jsapi"></script>
  <div id="chart_div"></div>

google.load('visualization', '1', {packages: ['corechart', 'bar']});
google.setOnLoadCallback(drawBasic);
function drawBasic() {
var data = google.visualization.arrayToDataTable([
        ['Method', 'Box Office', 'Call Center', 'Group Sales', 'Subscription',
         'Web', { role: 'annotation' } ],
['Day 0', 960, 146, 0, 0, 406, ''],
['Day 1', 690, 191, 25, 4, 457, ''],
['Day 2', 189, 191, 35, 4, 443, ''],
['Day 3', 185, 138, 14, 3, 443, ''],
['Day 4', 130, 135, 21, 3, 416, ''],
['Day 5', 181, 216, 22, 9, 659, ''],
  */
      ]);
      var options = {
        width: '100%',
        height: 500,
        legend: { position: 'top', maxLines: 3 },
        bar: { groupWidth: '75%' },
        isStacked: 'percent'
      };
      var chart = new google.visualization.BarChart(document.getElementById('chart_div'));
      chart.draw(data, options);
    }

这是图表的工作版本。

google.load('visualization', '1', {packages: ['corechart']});
google.setOnLoadCallback(drawChart);
function drawChart() {
    var data =google.visualization.arrayToDataTable([
        ['Method', 'Box Office', 'Call Center', 'Group Sales', 'Subscription',
         'Web', { role: 'annotation' } ],
['Day 0', 960, 146, 0, 0, 406, ''],
['Day 1', 690, 191, 25, 4, 457, ''],
['Day 2', 189, 191, 35, 4, 443, ''],
['Day 3', 185, 138, 14, 3, 443, ''],
['Day 4', 130, 135, 21, 3, 416, ''],
['Day 5', 181, 216, 22, 9, 659, '']
      ]);
     var options = {
         width: 600,
        height: 400,
        isStacked: true,
        legend: { position: 'top', maxLines: 3 },
         seriesType: "bars",
      };
      var chart = new google.visualization.ComboChart(document.getElementById('chart_div'));
      chart.draw(data, options);
}

http://jsfiddle.net/n53tqsnw/

您在使用google.visualization.BarChart调用图表时犯了错误,该图表应该是google.vislation.ComboChart.

希望这对你有帮助。