[ Launch: Arc Pie ] 5f695874e44f625e9cb49672ec837ce2 by rizafr
-
-
Save rizafr/5f695874e44f625e9cb49672ec837ce2 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,"ajax-caching":true} |
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 = 300, //width | |
| h = 300, //height | |
| r = 100, //radius | |
| ir = 50, | |
| pi = Math.PI, | |
| color = d3.scale.category20c(); | |
| data = [{"label":"one", "value":20}, | |
| {"label":"two", "value":50}, | |
| {"label":"three", "value":30}]; | |
| 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.value; }) | |
| .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) { | |
| return "translate(" + arc.centroid(d) + ")"; | |
| }) | |
| .attr("text-anchor", "middle") | |
| .text(function(d, i) { return data[i].label; }); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment