KateJean
KateJean

Reputation: 428

d3.json not parsing my JSON correctly?

I am attempting to switch my code to allow an external JSON file to be referenced. See my fiddle, line 62.

However, I keep getting the error

Uncaught TypeError: Cannot read property 'nodes' of undefined at update 

meaning (I assume) that my json file somehow isn't getting parsed correctly. How do I go about fixing this?

Upvotes: 0

Views: 103

Answers (1)

sparta93
sparta93

Reputation: 3854

You cannot use the variable with json data directly in the d3.json call. It needs to be an url to a json file either someplace online or somewhere on your local machine.

So instead, all you have to do is get rid of the d3.json call and use the data variable directly.

var graph = data; //set your graph variable equal to your data var

update(graph);  // pass it directly to your update function. No need for d3.json

JSFiddle - https://jsfiddle.net/b4to2mqe/

Upvotes: 1

Related Questions