简体   繁体   中英

d3js multiple targets to a single node

I'm using d3js to create a visual that is supposed to help me show dependencies of certain javascript files.

The current format that shows the relationship between the source and the target in d3 is:

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

Could anyone that is experienced with d3 and/or Javascript tell me how I can change the code so I can add multiple targets to look like:

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

If you want to list several values in the target attributes, you can use a Javascript array

like so :

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

The array is created directly using the [] constructor. Actually links is also an array

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM