javascript - How to import json data in D3? -


how import json file in d3?

i did d3.json("temp.json");

but how access data set in further code?

so far have tried:

var data=d3.json("temp.json"); 

but using .data(data) did not work in rest of code. example, here

var rows = g.selectall("g.row") .data(data) .enter().append("g") .attr({   "class": "row",   "transform": function(d, i) {     var tx = 170 + * squarewidth;     var ty = 150;     return "translate(" + [tx, ty] + ")"   } }); 

it not able access data. copy pasted json variable , worked fine. there no problem data itself.

the function d3.json() asynchronous. thus, have wait data received before reading data variable. reason why, when dealing asynchronous data, practice inside d3.json() function

d3.json("temp.json", function(error, data){     //use data here }) // not use data anymore 

Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -