Reputation: 11
I am trying to convert this regular bar chart into a stacked column chart. I have been playing around with JSfiddle for a while and just can't get it.
I'm assuming my issue is rather small but I just can't identify it. Any help would be appreciated. Thanks!
<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);
}
Upvotes: 1
Views: 157
Reputation: 1575
Here is the working version of your chart.
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);
}
You are making mistake at calling the chart with google.visualization.BarChart which should be google.visualization.ComboChart.
Hope this will help you.
Upvotes: 0