Reputation: 146
Can someone direct me to any resource to make exploded pie chart on click with d3.js just like we have the pie charts in kendo ui. I can't use kendo as I have very specific requirements that Kendo UI can't fulfill. I have made my pie chart with all the required functionality but can't really find any resource to make it explode on click.
Thanks in advance.
Upvotes: 1
Views: 5232
Reputation: 671
I strongly recommend using Michael Bostock's examples gallery (he is the author of D3) as a starting point when developing a new D3 visualisation.
Eg. Use the code sample from: http://bl.ocks.org/mbostock/3887235.
Edit: To add the "explosion" you just need a little translation applied to each segment.
var explode = function(x,index) {
var offset = (index==5) ? 80 : 0;
var angle = (x.startAngle + x.endAngle) / 2;
var xOff = Math.sin(angle)*offset;
var yOff = -Math.cos(angle)*offset;
return "translate("+xOff+","+yOff+")";
}
g.append("path")
.attr("d", arc)
.style("fill", function(d) { return color(d.data.age); })
.attr("transform", explode);
See it in a JsFiddle: http://jsfiddle.net/zephod/L4pyk79e/2/
Upvotes: 2