如何让Google图表显示原点来自最小值而不是零的区域图?
在这个例子中,我希望蓝色区域从-2000开始。
这是小提琴.. http://jsfiddle.net/C87eD/
function drawVisualization() {
// Some raw data (not necessarily accurate)
var data = google.visualization.arrayToDataTable([
['Month', 'Bolivia', 'Ecuador', 'Madagascar', 'Papua New Guinea', 'Rwanda'],
['2004/05', 165, 938, 522, 998, 450],
['2005/06', 135, 1120, 599, 1268, 288],
['2006/07', 157, 1167, 587, 807, 397],
['2007/08', 139, 1110, 615, 968, 215],
['2008/09', 136, 691, 629, 1026, 366]
]);
// Create and draw the visualization.
var ac = new google.visualization.AreaChart(document.getElementById('visualization'));
ac.draw(data, {
title : 'Monthly Coffee Production by Country',
isStacked: true,
width: 600,
height: 400,
vAxis: {
title: "Cups",
viewWindowMode:'explicit',
viewWindow: {
min: -2000
}
},
hAxis: {title: "Month"}
});
}
答案 0 :(得分:2)
一种可能性是使用值为-2000和2000的两个虚拟列将第一个有用值推送到0:
var data = google.visualization.arrayToDataTable([
['Month', 'dummy1', 'dummy2', 'Bolivia', 'Ecuador', 'Madagascar', 'Papua New Guinea', 'Rwanda'],
['2004/05', -2000, 2000, 165, 938, 522, 998, 450],
['2005/06', -2000, 2000, 135, 1120, 599, 1268, 288],
['2006/07', -2000, 2000, 157, 1167, 587, 807, 397],
['2007/08', -2000, 2000, 139, 1110, 615, 968, 215],
['2008/09', -2000, 2000, 136, 691, 629, 1026, 366]
]);
并添加从图例中删除虚拟系列的选项:
series: {
0: {
visibleInLegend: false
},
1: {
visibleInLegend: false
}
}