d3js多个目标到单个节点

时间:2018-08-21 20:35:56

标签: javascript arrays class d3.js

我正在使用d3js创建一个可视化图形,可以帮助我显示某些JavaScript文件的依赖性。

在d3中显示源和目标之间关系的当前格式为:

var links = [
  { source: "A", target: "X"},
  { source: "Z", target: "Y"},
  { source: "A", target: "Z"},
  { source: "A", target: "W"},
];

任何有d3和/或Java经验的人都可以告诉我如何更改代码,以便可以添加多个目标,就像这样:

var links = [
  { source: "A", target: "X", "Y", "Z"},
  { source: "Z", target: "Y"},
  { source: "A", target: "Z"},
  { source: "A", target: "W"},
];

1 个答案:

答案 0 :(得分:0)

如果要在target属性中列出几个值,则可以使用Javascript array

像这样:

var links = [
  { source: "A", target: ["X", "Y", "Z"]},
  { source: "Z", target: "Y"},
  { source: "A", target: "Z"},
  { source: "A", target: "W"},
];

直接使用[]构造函数创建数组。实际上links也是一个数组