[ Launch: Arc Pie ] 5260888 by ingenioustechie
-
-
Save muke5hy/5260888 to your computer and use it in GitHub Desktop.
Arc Pie
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| {"description":"Arc Pie","endpoint":"","display":"svg","public":true,"require":[],"fileconfigs":{"inlet.js":{"default":true,"vim":false,"emacs":false,"fontSize":12},"_.md":{"default":true,"vim":false,"emacs":false,"fontSize":12},"config.json":{"default":true,"vim":false,"emacs":false,"fontSize":12}},"fullscreen":false,"play":false,"loop":false,"restart":false,"autoinit":true,"pause":true,"loop_type":"period","bv":false,"nclones":15,"clone_opacity":0.4,"duration":3000,"ease":"linear","dt":0.01} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var w = 200, //width | |
| h = 100, //height | |
| r = 100, //radius | |
| ir = 20, | |
| pi = Math.PI, | |
| color = d3.scale.category20c(); | |
| data = [{"name":"BJP", "seats":30}, | |
| {"name":"INC", "seats":50}, | |
| {"name":"Others", "seats":10}]; | |
| var vis = d3.select("svg") | |
| .data([data]) | |
| .attr("width", w) | |
| .attr("height", h) | |
| .append("svg:g") | |
| .attr("transform", "translate(" + r + "," + r + ")") | |
| var arc = d3.svg.arc() | |
| .outerRadius(r) | |
| .innerRadius(ir); | |
| var pie = d3.layout.pie() | |
| .value(function(d) { return d.seats; }) | |
| .startAngle(-90 * (pi/180)) | |
| .endAngle(90 * (pi/180)); | |
| var arcs = vis.selectAll("g.slice") | |
| .data(pie) | |
| .enter() | |
| .append("svg:g") | |
| .attr("class", "slice"); | |
| arcs.append("svg:path") | |
| .attr("fill", function(d, i) { return color(i); } ) | |
| .attr("d", arc); | |
| arcs.append("svg:text") | |
| .attr("transform", function(d) { | |
| d.innerRadius = 0; | |
| d.outerRadius = r; | |
| return "translate(" + arc.centroid(d) + ")"; | |
| }) | |
| .attr("text-anchor", "middle") | |
| .text(function(d, i) { return data[i].name; }); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment