我需要生成如下图表:
具体来说,我想在一段时间内显示正值和负值(可能是小时,分钟等)并显示如下。
我可以发誓我前几天在Google Visualization API Gallery看到了这样的事情,但我现在找不到它,甚至不确定这种图表是什么。
首先,你知道这种图表的名称是什么,所以我可以找到文档吗?其次,有没有办法用Google Visualization API实现这样的图表?如果没有,是否有另一种常见的网络图表解决方案,我可以用它实现这个目标吗?
感谢您的时间。
答案 0 :(得分:11)
这称为“堆积条形图”,确实可以使用Google Visualization API创建。
只需使用“isStacked”属性(此处描述; http://code.google.com/apis/visualization/documentation/gallery/barchart.html)。
以下是一些示例代码(基于Google提供的默认条形图示例,并更新以显示isStacked的使用以及示例中的一些示例数据);
function drawVisualization() {
var data = new google.visualization.DataTable();
data.addColumn('string', 'Month');
data.addColumn('number');
data.addColumn('number');
data.addRows(12);
data.setCell(0, 0, 'January');
data.setCell(1, 0, 'February');
data.setCell(2, 0, 'March');
data.setCell(3, 0, 'April');
data.setCell(4, 0, 'May');
data.setCell(5, 0, 'June');
data.setCell(6, 0, 'July');
data.setCell(7, 0, 'August');
data.setCell(8, 0, 'September');
data.setCell(9, 0, 'October');
data.setCell(10, 0, 'November');
data.setCell(11, 0, 'December');
data.setCell(0, 1, 19);
data.setCell(1, 1, 18);
data.setCell(2, 1, 20);
data.setCell(3, 1, 19);
data.setCell(4, 1, 18);
data.setCell(5, 1, 20);
data.setCell(6, 1, 19);
data.setCell(7, 1, 18);
data.setCell(8, 1, 20);
data.setCell(9, 1, 19);
data.setCell(10, 1, 18);
data.setCell(11, 1, 20);
data.setCell(0, 2, -12);
data.setCell(1, 2, -13);
data.setCell(2, 2, -11);
data.setCell(3, 2, -12);
data.setCell(4, 2, -13);
data.setCell(5, 2, -11);
data.setCell(6, 2, -12);
data.setCell(7, 2, -13);
data.setCell(8, 2, -11);
data.setCell(9, 2, -12);
data.setCell(10, 2, -13);
data.setCell(11, 2, -11);
data.setCell(0, 2, -12);
data.setCell(1, 2, -13);
data.setCell(2, 2, -11);
// Create and draw the visualization.
new google.visualization.ColumnChart(document.getElementById('visualization')).
draw(data,
{title:"S&P 500 Up/Down Performance Since 1980",
width:600, height:400,
isStacked:"true",
legend:"none" }
);
}
结果......
答案 1 :(得分:0)
使用ColumnChart而不是BarChart:
var chart = new google.visualization.ColumnChart(document.getElementById('chart_div'));