I'm looking to use d3.js to create a diagram using the tree layout. Instead of the typical flare json structure with hierarchical children, I have an array representing different timesteps that I want to transform into a tree. My plan is to adjust the children function of the tree layout like this:
var tree = d3.layout.tree()
.children(function(d,i) {
return data[(i+1)];
})
However, when I implement this change, only one element is displayed in the tree. I expected it to iterate over every element when calling tree.nodes
on data[0]
. What am I missing here?
To better explain my goal: I aim to convert an array such as [ele1, ele2, ele3]
into a tree graph that looks like:
ele1-->ele2-->ele3