gpt4 book ai didi

javascript - d3.js sankey 图 - 使用 multi dime 数组作为节点

转载 作者:行者123 更新时间:2023-11-30 05:33:15 27 4
gpt4 key购买 nike

我一直在使用 Google Chart 的 Sankey Diagram 开发一个应用程序,并且我在网络应用程序上成功地创建了一个 Sankey Diagram 示例。但是我对布局不满意,我在网上搜索并找到了 d3.js 的 Sankey Diagram 插件。它看起来非常好,我测试了来自 here 的示例代码应用程序.

在代码中,它调用外部JSON文件将其用作节点:

d3.json("sankey-formatted.json", function(error, graph) { ... });

在我开发的第一个应用程序中,我从这样的多维数组中获取我的节点:

//rows is the multidimensional array
//i got this from the example on Google Charts
data.addRows(rows);

多维数组是来自 AJAX 调用的对象集合。

如何将此数组用于桑基图?我可以不调用外部文件吗?

最佳答案

我设法回答了我自己的问题(愚蠢的我)。我会将其发布以备将来使用。

如果您已经有一个保存数据的变量(即数组),请直接使用它。

在我的例子中,原始代码:

d3.json("sankey-formatted.json", function(error, graph) {

//sankey is an object, as well as the graph
sankey
.nodes(graph.nodes)
.links(graph.links)
.layout(32);

// ... other codes
});

改成

// this time, nodes and links are the variables
// that holds the arrays to be used by the chart
// remove the encapsulation of d3.json
sankey
.nodes(nodes)
.links(links)
.layout(32);

// ... other codes

希望这对以后的观点有所帮助。

关于javascript - d3.js sankey 图 - 使用 multi dime 数组作为节点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25562189/

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