Recently encountered a strange error that seems to be originating from asynchronously loading my data json file.
To demonstrate, check out this jsfiddle link with my code and hard-coded data.
The goal is to transition from hardcoding the data to loading it from a json file, as shown in the following code snippet:
var nodes;
d3.json("nodes.json", function(json){
nodes = json;
});
Although this code eventually works when I call the update function within this block and the data gets rendered, I keep encountering an "Uncaught TypeError: Cannot read property 'length' of undefined," which I am keen on resolving.
This is the error stack displayed in Chrome:
Uncaught TypeError: Cannot read property 'length' of undefined
bind @ d3.js:844
d3_selectionPrototype.data @ d3.js:900
update @ example.ts:99
(anonymous function) @ example.ts:280
It's worth noting that the error triggers at this line of code:
var points = points = plot.selectAll("circle").data(nodes);
I have simplified the fiddle by removing unnecessary components for clarity.