X-jo
X-jo

Reputation: 601

embed json file within d3.js

http://bl.ocks.org/mbostock/4339083 am using this

instead of d3.json("/d/4063550/flare.json", function(error, flare) {

how do i make it use the json file within the html, like say i have

var jsonData = [{
 "name": "A",
 "children": [  
  {"name": "A1", "children": [{"name": "A12"},{"name": "A13"},{"name": "A14"}]  },
  {"name": "A2",    "children": [{"name": "A22"},{"name": "A23"},{"name": "A24"}]  }
 ]
}];

and i want to use this instead of an external json file, how do i achieve this ?

Upvotes: 2

Views: 1924

Answers (1)

Manoj
Manoj

Reputation: 1890

Solution:

1.you can assign the JSON data to variable name then You can build the tree layout

2.use one function to get the JSON data

Fiddle for 1 solution

Fiddle for 2 solution

    var root = getData(),
    nodes = cluster.nodes(root),
    links = cluster.links(nodes);

Upvotes: 3

Related Questions