2
votes

I am working on a graph which basically contains at least 150 nodes using D3 Javascript. The idea can be described as follows:

One node is connected to 100 nodes. 49 nodes of these 100 nodes are connected to other 49 nodes.

Let's clarify it. I know 100 people. 49 people of them have birthdays. Each of which represents a node.

In such a way, I could manage to link them together using source and target through some arrays in Javascript. I think I am missing something very important to understand in Force-Directed Graph in D3. As far as I am aware, the links can be implemented with source and target. My problem is I cant understand how I can link these links to these nodes. I do not know on what basis I can create an array to hold my name, peoples' names and their birthdays so they can be linked together. In my graph, it gives me the right person but the wrong birthday. Could anyone please guide me the right way how to do with this matter. I am following this tutorial: and could not understand how I can create an array to add the information such as: name, peoples names and birthday.

http://bl.ocks.org/mbostock/4062045

Your assistance would be very much appreciated.

1
I am afraid you will need to post what you have tried so far on jsfiddle or some other place with some mock data for us to be able to guide you. - musically_ut
The problem is I have a big amount of data. I will try to manage to do so. - user2864315

1 Answers

4
votes

The way the nodes and links are linked is by index. That is, if target: 0, it means that the target node of that link is the first one in the list of nodes, as passed to the force layout. You can add any data you need to both links and nodes -- for links, the nodes are also available through link.source and link.target.

Alternatively, you can specify the source and target of a link as the object itself -- this is actually what D3 does internally when you pass the links to the force layout. As it can't work with the indices as such, they are replaced with the resolved node objects (this is why you can access the actual objects through the links).

If you're specifying the graph structure through external data (e.g. JSON), then you should use indices to identify nodes in links. If you're generating the data structure in Javascript, you could use references to the actual objects instead.