1

I am generating an zoomable chart by using d3.js.

chart data is being received as json object. how to change the following code to work with JSON object

d3.json("mydata.json", function(json) {
//TODO: 
});

instead of file name "msdata.json" I want to use Json object. please help me how to do this.

3

1 Answer 1

2

If you already have a JSON string (there's no such thing as JSON object) in the script, you can remove your d3.json request and use JSON.parse to convert the JSON string to an object (usually it's an array) like so:

var data = JSON.parse(yourJSONString);

Then you can use it to compute data joins or whatever you want to do with it in d3:

someSelection.data(data).enter()... // etc.
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.