score:0

Accepted answer

It is happening because you are using

d3.json("nodes.json", function(json){
    nodes = json;
});

Which is a aync call so initially nodes will be undefined because var nodes; gives nothing to it. During the call and your var points = points = plot.selectAll("circle").data(nodes); already run and throw an error Cannot read property 'length' of undefined.

You can do one thing :-

d3.json("nodes.json", function(json){
   //put your complete logic here
});

Hope it helps :)

score:0

Your fiddle does not throw this error. But most likely your data isn't ready by the time you are trying to create the circles. Put all the logic that does the creation of the circles (or depends on data) into the callback function of

d3.json("nodes.json", function(json){
    //PUT CODE HERE
}); 

and this should work as this code does not get run until JSON is loaded.


Related Query

More Query from same tag