Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

d3 piechart from local json variable

Tags:

json

d3.js

I am trying to create a donut chart using json from a local variable (rather than an external file) I have seen this post but am having a hard time adjusting my code in the same way

In the above example

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

was replaced with

root = JSON.parse( myjson );

which does not fix my problem

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

Fiddle

like image 628
jotamon Avatar asked Oct 31 '13 21:10

jotamon


Video Answer


1 Answers

  1. Rename your JSON variable to data.
  2. Delete the d3.json call (but keep the code within it).

Complete jsfiddle here. You also need to append your SVG to "body" and not "#body".

like image 149
Lars Kotthoff Avatar answered Sep 29 '22 13:09

Lars Kotthoff