我想弄清楚如何自定义各个Sankey Chart起始块的大小?
例如,我希望煤的垂直起始线以及通道的百分比小于天然气垂直起始线。我曾尝试查看Google开发文档,但我只看到有关如何扩展,展开和更改Sankey Diagram颜色的参考。
这是我目前通过JSFiddle编写的代码:
google.setOnLoadCallback(drawChart);
function drawChart() {
var data = new google.visualization.DataTable();
data.addColumn('string', 'From');
data.addColumn('string', 'To');
data.addColumn('number', 'Weight');
data.addRows([
[ 'Nuclear Electric Power', 'Electricity Retail Sales', 100 ],
[ 'Renewable Energy', 'Electricity System Energy Losses', 29 ],
[ 'Coal', 'Electricity System Energy Losses', 96 ],
[ 'Natural Gas', 'Electricity System Energy Losses', 44 ],
[ 'Petroleum', 'Transportation', 87 ],
[ 'Electricity System Energy Losses', 'Commercial', 69 ],
[ 'Electricity System Energy Losses', 'Residential', 69 ],
[ 'Electricity System Energy Losses', 'Industrial', 28 ],
[ 'Renewable Energy', 'Commercial', 1 ],
[ 'Renewable Energy', 'Residential', 8 ],
[ 'Renewable Energy', 'Industrial', 61 ],
[ 'Coal', 'Industrial', 4 ],
[ 'Natural Gas', 'Commercial', 12],
[ 'Natural Gas', 'Residential', 13],
[ 'Natural Gas', 'Industrial', 30],
[ 'Natural Gas', 'Transportation', 1],
[ 'Petroleum', 'Commercial', 2 ],
[ 'Petroleum', 'Residential', 2 ],
[ 'Petroleum', 'Industrial', 9 ]
//MAKE SURE TO NOT PUT A COMMA ON THE LAST BLOCK
]);
// Sets chart options.
var options = {
width: 600,
};
//var options = {
//height: 400,
//sankey: {
//node: {
//colors: colors
//},
//link: {
//colorMode: 'gradient',
//colors: colors
//}
//}
//};
// Instantiates and draws our chart, passing in some options.
var chart = new google.visualization.Sankey(document.getElementById('sankey_basic'));
chart.draw(data, options);
}
答案 0 :(得分:1)
The vertical line for coal (the rectangle is known as a Node) is sized based on the value/weight in your data. If you look at Coal it has a combined value or 100 ([ 'Coal', 'Electricity System Energy Losses', 96 ] + [ 'Coal', 'Industrial', 4 ]). Decrease the value from 96 to 50 (example) and the Node height changes. Hope this helps.