gpt4 book ai didi

javascript - 为什么highcharts桑基图有时会将多个节点名称相同但Id不同的节点合并为一个并隐藏线条?

转载 作者:行者123 更新时间:2023-12-02 20:49:11 24 4
gpt4 key购买 nike

对于下面的代码片段,

const data = [
{"from":"step2_FRANCE","to":"step3_SPAIN","weight": 2},
{"from":"step3_SPAIN","to":"step4_PORTUGAL","weight":2},
{"from":"step2_PORTUGAL","weight":1, to: "step3_SPAIN" },
{"from":"step2_FRANCE","weight":1},
{"from":"step2_SPAIN","weight":1},
{"from":"step2_ENG","weight":1},
{"from":"step2_PORTUGAL","weight":1, to: "step3_SPAIN"},
{"from":"step2_FRANCE","weight":1},
];

const nodes = [
{"id":"step2_PORTUGAL","name":"Portugal","column":1, "color":"#ede042"},
{"id":"step2_FRANCE","name":"France","column":1, "color":"#cb65dc"},
{"id":"step2_SPAIN","name":"Spain","column":1,, "color":"#6493f1"},
{"id":"step2_ENG","name":"England", "column":1, "color":"#6ed4eb"},
{"id":"step3_SPAIN","name":"Spain","column":2, "color":"#6493f1"},
{"id":"step4_PORTUGAL","name":"Portugal","column":3, "color":"#ede042"}
];


Highcharts.chart('container', {
title: {
text: 'Highcharts Sankey Diagram'
},
accessibility: {
point: {
valueDescriptionFormat: '{index}. {point.from} to {point.to}, {point.weight}.'
}
},
series: [{
data,
nodes,
type: 'sankey',
name: 'Sankey demo series'
}]
});

我得到这样的输出:Incorrect sankey chart output我期待的是:

  1. 第 1 列中的法国、葡萄牙、西类牙和英格兰(ID 包含 step2_..)
  2. 西类牙位于第 2 列(ID 包含 step3_..)
  3. 葡萄牙位于第 3 列(ID 包含 step4_..)

节点选项中,还显示了列号和名称。

如果我注释掉 Step2.. 中的一个节点,我会得到部分正确的图表。

const nodes = [
{"id":"step2_PORTUGAL","name":"Portugal","column":1,"color":"#ede042"},
// {"id":"step2_FRANCE","name":"France","column":1, "color":"#cb65dc"},
{"id":"step2_SPAIN","name":"Spain","column":1, "color":"#6493f1"},
{"id":"step2_ENG","name":"England", "column":1, "color":"#6ed4eb"},
{"id":"step3_SPAIN","name":"Spain","column":2, "color":"#6493f1"},
{"id":"step4_PORTUGAL","name":"Portugal","column":3, "color":"#ede042"}
];

Partially correct sankey chart

我无法理解为什么图表会这样。我猜我传递数据/节点的方式有问题。如果有人能指出我正确的方向,我将不胜感激。

最佳答案

在节点选项中从 0 开始设置列可以解决问题。

演示:https://jsfiddle.net/BlackLabel/fkshbmdv/

const nodes = [{
"id": "step2_PORTUGAL",
"name": "Portugal",
//"column": 0,
"color": "#ede042"
}, ...
];

实际上在这种情况下不需要使用列属性:https://jsfiddle.net/BlackLabel/n53Ljcgd/

API:https://api.highcharts.com/highcharts/series.sankey.nodes.column

关于javascript - 为什么highcharts桑基图有时会将多个节点名称相同但Id不同的节点合并为一个并隐藏线条?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61658491/

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