0

I am using this: http://mbostock.github.io/d3/talk/20111018/partition.html

instead of d3.json("flare.json", function(root) {

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

var json = [{
"name": "flare",
"children": [
{"name": "analytics",
"children": [
{"name": "cluster","children": [{"name": "AgglomerativeCluster", "size": 3938},
{"name": "CommunityStructure", "size": 3812},
{"name": "HierarchicalCluster", "size": 6714},
{"name": "MergeEdge", "size": 743}
]
},  

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

Link to json file: http://mbostock.github.io/d3/talk/20111018/flare.json

Any JSFiddle example please?

Thank you.

1
  • This is not very complicated fix, if you can share ur code in fiddle or plunker. I can edit it. Commented Jun 30, 2014 at 8:59

1 Answer 1

2

You will achieve this by two method:

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

2.use one function to get the JSON data

Fiddle for 1 solution

var root = json;

Fiddle for 2 solution

var root = getData();
  var g = vis.selectAll("g")
      .data(partition.nodes(root))
    .enter().append("svg:g")
      .attr("transform", function(d) { return "translate(" + x(d.y) + "," + y(d.x) + ")"; })
      .on("click", click);
Sign up to request clarification or add additional context in comments.

2 Comments

How to get this working with version 4?, the layout partition does no longer exist and its replacement does not contain a value property

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.