2
如果我画线图是没有问题的,但我想这个对色阶柱状图。(https://developers.google.com/chart/interactive/docs/gallery/histogram)如何在Google图表上绘制垂直线到直方图?
对于线型图;
var chart = new google.visualization.LineChart(document.querySelector('#chart_div'));
对于直方图;
var chart = new google.visualization.Histogram(document.querySelector('#chart_div'));
其他代码;
function drawChart() {
var data = new google.visualization.DataTable();
data.addColumn('string', 'Name');
data.addColumn({type: 'string', role: 'annotation'});
data.addColumn('number', 'Value');
data.addRows([
['Foo', null, 4],
['Bar', null, 3],
['Baz', null, 7],
['Bat', null, 9],
['Cad', 'Vertical line here', 9],
['Qud', null, 2],
['Piz', null, 6]
]);
var chart = new google.visualization.Histogram(document.querySelector('#chart_div'));
chart.draw(data, {
height: 300,
width: 400,
annotation: {
// index here is the index of the DataTable column providing the annotation
1: {
style: 'line'
}
}
});
}
对于未来的用户:这也可以用来制作动画上线图的“注释”行 - 我找不到任何办法让谷歌图为注释的变化位置设置动画效果,但在上面代码中绘制的线的X位置进行动画处理非常简单。感谢您的正确方向,dustqm! – roguenet