Question

I am trying to create a d3 force-directed graph (http://mbostock.github.com/d3/ex/force.html). Here is the simple JSON file containing my data.

{"nodes":[{"name":"Node1","group":1}, {"name":"Node2","group":1}],

    "links":[{"source":1,"target":2,"value":2}]}

I have two nodes in the same group. I am trying to also create a link between the two nodes. However, my page remains blank (and I am sure that other parts other than the JSON are correct).

What is a "group"? Why do edges have both a "source" and a "target" - and what are these values? Why do links have a "value"? Aren't the links just unweighted edges? I'm having trouble understand the JSON structure of data storage.

Was it helpful?

Solution

In the d3 force-directed graph example, the 'value' of links is mapped to the stroke width of the edges and the 'group' of nodes is mapped to the color of the nodes. The integer value of 'source' and 'target' in links refers to the array index of the corresponding node in nodes (https://github.com/mbostock/d3/wiki/Force-Layout#wiki-links).

If you change source links to

 "links":[{"source":0,"target":1,"value":2}]}

it, d3 should render an edge between the two nodes.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top