I'm trying to change my visualization script to be more like the Modifying a Force Layout Example. Since I don't have fixed nodes like a, b and c
to add I read a json file
to fill the nodes
and links
array.
d3.json("mock.json", function(error, json) {
if (error)
throw error;
nodes = nodes.concat(json.nodes);
links = links.concat(json.links);
start();
});
nodes
and links
have the right size, meaning nodes contains 26 nodes
and links 37 links
. Now I want to simply visualize them using line
and circle
elements.
function start() {
link = link.data(force.links(), function(d) { return d.source.id + "-" + d.target.id; });
link.enter().append("line").attr("class", "link");
link.exit().remove();
node = node.data(force.nodes(), function(d) { return d.id;});
node.enter().append("circle").attr("class", "node").attr("r", 8);
node.exit().remove();
force.start();
}
This is very simular to the example and I don't really understand why this won't work. I provide a demo with the mock. Is there an issue because I use concat()
and not push()
or is there anything else wrong?