gpt4 book ai didi

javascript - 如何确定桑基图起始 block 的大小?

转载 作者:太空宇宙 更新时间:2023-11-04 10:54:44 25 4
gpt4 key购买 nike

我想知道如何自定义单个 Sankey Chart 起始 block 的大小?

例如,我希望煤炭垂直起跑线连同路径比天然气垂直起跑线小一个百分比。我曾尝试查看 Google 开发文档,但我只看到有关如何扩展、展开和更改桑基图颜色的引用。

enter image description here

这是我当前通过 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);
}

最佳答案

煤炭的垂直线(矩形称为节点)根据数据中的值/权重调整大小。如果您查看煤炭,它有一个组合值或 100([“煤炭”,“电力系统能量损失”,96] + [“煤炭”,“工业”,4])。将值从 96 减小到 50(示例),节点高度会发生变化。希望这会有所帮助。

关于javascript - 如何确定桑基图起始 block 的大小?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34728758/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com