How to create an area chart which has both normal area and "upside-down" area?
Already looked at their docs, but didn't find a solution there.
The end result should look like this:
You can see my current status in this jsfiddle.
google.charts.load('current', {'packages':['corechart']});
google.charts.setOnLoadCallback(drawChart);
function drawChart() {
var data = google.visualization.arrayToDataTable([
['Year', 'Blue', 'Red'],
['0', 0, 20],
['2', 0, 20],
['4', 0, 20],
['6', 1, 19],
['8', 2, 18],
['10', 3, 17],
['12', 4, 16],
['14', 5, 15],
['16', 6, 14],
['18', 7, 13],
['20', 8, 12],
['22', 9, 11],
['24', 10, 10]
]);
var options = {
title: 'Company Performance',
hAxis: {title: 'Year', titleTextStyle: {color: '#333'}},
vAxis: {minValue: 0}
};
var chart = new google.visualization.AreaChart(document.getElementById('chart_div'));
chart.draw(data, options);
}
答案 0 :(得分:2)
Google Charts AreaChart从数据线向下或向上填充区域。但是基线(目前)仅适用于轴,你实际上需要两个不同的基线,一个在顶部用于一个系列,一个在底部用于另一个系列,所以你必须做一些技巧来得到你的想。
基本上,将每个系列定位到不同的轴,每个轴都有自己的基线,并使用相同的viewWindow对齐两个轴。像这样:
var options = {
title: 'Company Performance',
hAxis: {title: 'Year', titleTextStyle: {color: '#333'}},
vAxes: {
0: {viewWindow: { min: 0, max: 20 }, baseline: 0},
1: {viewWindow: { min: 0, max: 20 }, baseline: 20},
},
series: {
1: { targetAxisIndex: 1 }
}
};