我需要生成这样的图表:
具体来说,我想显示一段时间(可以是一小时、一分钟等)的正值和负值,并像这样显示。
我可以发誓我在 Google Visualization API Gallery 上看到过类似的东西前几天找到了,但是现在找不到了,甚至不知道这种图表叫什么名字。
首先,您知道这种图表叫什么吗,以便我可以找到文档?其次,有没有办法用Google Visualization API来实现这样的图表?如果没有,是否有另一种常见的网络图表解决方案可以实现这一目标?
感谢您的宝贵时间。
最佳答案
这称为“堆叠条形图”,确实可以使用 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" }
);
}
结果...
关于charts - Google Visualization API 中的正/负图表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5208904/