Hello All instead of simple Circles, i want to add pie charts in my Pack layout.
Lets Suppose this is my pie chart data and pie layout
var data=[2,3,4,5]
var arc = d3.svg.arc() .outerRadius(50) .innerRadius(0);
var pie = d3.layout.pie() .sort(null)
.value(function(d) { return d; });
And this is how the packlayout draws the circle
var circle = svg.selectAll("circle")
.data(nodes1)
.enter().append("circle")
.attr("class", function(d) { return d.parent ? d.children ? "node" : "node node--leaf" : "node node--root"; })
.style("fill", function(d) { return d.children ? color(d.depth) : null; })
.on("click", function(d) { if (focus !== d) zoom(d), d3.event.stopPropagation(); });
Can anyone please explain me how instead of appending circles in pack layout i could rather append paths and make pie charts out of it?![enter image description here][1]
Instead of using the pack layout results directly, you can use the
r
value output from the pack layout to define theouterRadius
of yourarc
generator. Then, instead of appending svgcircle
elements to the chart, you can append svgg
elements, and append each of the arcs inside that:Full example: http://bl.ocks.org/jsl6906/4a1b818b64847fb05d56
Relevant code: