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

时间:2015-10-29 03:42:31

标签: javascript charts google-visualization

我正在尝试将此常规条形图转换为堆积柱形图。我一直在玩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);
    }

1 个答案:

答案 0 :(得分:0)

以下是图表的工作版本。

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.visualization。 ComboChart

希望这会对你有所帮助。