D3 piechart from json local variable

I am trying to create a donut diagram using json from a local variable (not an external file), I saw this post , but it is difficult for me to configure my code in the same way

In the example above

d3.json("flare.json", function(error, root) { 

has been replaced by

 root = JSON.parse( myjson ); 

which does not fix my problem

Check out the script below where my data is loaded as a variable called myJson. How can I use this data for a donut?

Fiddle

+7
json
source share
1 answer
  • Rename the JSON variable to data .
  • Remove the d3.json call (but keep the code inside it).

Fill out jsfiddle here . You also need to add SVG to "body", not "#body".

+11
source share

All Articles