How to layout a non-tree hierarchy with D3

后端 未结 4 1971
感情败类
感情败类 2020-12-13 04:41

D3 has a variety of layouts for directed graphs that are strict trees, such as the following:

A
|\\
B C
 / \\
D   E

I need to draw a hierar

4条回答
  •  醉话见心
    2020-12-13 05:21

    Speaking generally of trees and the data hierarchy, you just need to have "D" in the children list for both B and C.

    Creating your node list, make sure you have a unique id returned so that "D" doesn't appear twice.

    vis.selectAll("g.node").data(nodes, function(d) { return d.id; });
    

    Then when you call

    var links = tree.links(nodes)
    

    you should get D appearing as the "target" twice (with B and C as the "source" respectively) which results in two lines to the single node "D".

提交回复
热议问题