【问题标题】:How to assign the x-axis position of a node in a Sankey Diagram (D3) from the json file如何从 json 文件中分配桑基图 (D3) 中节点的 x 轴位置
【发布时间】:2014-05-10 06:42:22
【问题描述】:

我终于在 D3 中找到了一个桑基图,它允许节点在 x 轴上移动,但我想从 json 文件中分配一个值来固定特定位置的位置。

http://bl.ocks.org/d3noob/raw/5028304/

我想要做的是使用桑基图作为时间线。

【问题讨论】:

标签: javascript json d3.js sankey-diagram


【解决方案1】:

让我们将 x 坐标称为layer。 layer=0 将是左边缘,layer=n 将是右边缘。在JSON 文件的nodes 字段中,为每个节点添加键值对"layer": your_desired_x_as_integer。

然后去 sankey.js 文件找到函数componentsByBreadth.forEach。 将node.x = component.x + node.x; 行替换为:

if (node.layer) node.x=node.layer;
else node.x = component.x + node.x;

您也可以像这样定义层的密度,例如放置在层 0,1,2 或 0,4,8 上的节点将有一个中心节点和两个在 sankey 宽度的边缘,但 0,1,5 将没有。

如果您需要更多帮助,我的 D3 Sankey 应用程序中包含此功能以及其他功能:http://sankey.csaladen.es

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-07-23
    • 2019-08-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-04-13
    相关资源
    最近更新 更多