可能为重复问题:
有人可以帮我使用Google Charts创建一个简单的垂直条形图吗?
我正在使用新的Google Chart工具,并且想创建堆叠式条形图格式。
谷歌开发者网站提供了有关条形图格式的一些详细信息:https://developers.google.com/chart/interactive/docs/gallery/barchart
要使普通条形图堆叠,您需要使用isStacked: true
选项。您可以复制并粘贴以下代码到Chart Tools playground中查看工作示例:http://code.google.com/apis/ajax/playground/?type=visualization
function drawVisualization() {
// Create and populate the data table.
var data = google.visualization.arrayToDataTable([
['Year', 'Austria', 'Bulgaria', 'Denmark', 'Greece'],
['2003', 1336060, 400361, 1001582, 997974],
['2004', 1538156, 366849, 1119450, 941795],
['2005', 1576579, 440514, 993360, 930593],
['2006', 1600652, 434552, 1004163, 897127],
['2007', 1968113, 393032, 979198, 1080887],
['2008', 1901067, 517206, 916965, 1056036]
]);
// Create and draw the visualization.
new google.visualization.BarChart(document.getElementById('visualization')).
draw(data,
{title:"Yearly Coffee Consumption by Country",
width:600, height:400,
vAxis: {title: "Year"},
hAxis: {title: "Cups"},
isStacked: true}
);
}
根据你尝试展示的数据,你可能也对堆积面积图感兴趣。
此外,有一个问题提供了使用Chart Tools Image API创建堆积条形图的示例:Bar chart in Javascript: stacked bars + grouped bars
请注意,谷歌图表工具的Image Charts部分于2012年4月20日官方弃用。根据谷歌的弃用政策,图像图表仍将在一段时间内正常工作,但我建议您专注于上述交互式HTML5+SVG实现。