最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - What do the nodes, groups, and values mean in the JSON for a d3 force-directed graph? - Stack Overflow

programmeradmin4浏览0评论

I am trying to create a d3 force-directed graph (.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.

I am trying to create a d3 force-directed graph (http://mbostock.github./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.

Share Improve this question edited Jun 16, 2014 at 15:26 VividD 10.5k8 gold badges66 silver badges112 bronze badges asked Apr 6, 2012 at 2:11 dangerChihuahua007dangerChihuahua007 20.9k38 gold badges128 silver badges211 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 8

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./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.

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论