D3
OG
Old school D3 from simpler times
All examples
By author
By category
About
yanhann10
Full window
Github gist
donut
Built with
blockbuilder.org
<!DOCTYPE html> <head> <meta charset="utf-8"> <script src="https://d3js.org/d3.v3.min.js"></script> <style> body { margin:0;position:fixed;top:0;right:0;bottom:0;left:0; } </style> </head> <body> <script> // Feel free to change or delete any of the code you see in this editor! var w = 300; var h = 300; var dataset = [ 5, 10, 20, 45, 6, 25 ]; var outerRadius = w / 2; var innerRadius = 45; var arc = d3.svg.arc() .innerRadius(innerRadius) .outerRadius(outerRadius); var pie = d3.layout.pie(); //Easy colors accessible via a 10-step ordinal scale var color = d3.scale.category10(); //Create SVG element var svg = d3.select("body") .append("svg") .attr("width", w) .attr("height", h); //Set up groups var arcs = svg.selectAll("g.arc") .data(pie(dataset)) .enter() .append("g") .attr("class", "arc") .attr("transform", "translate(" + outerRadius + "," + outerRadius + ")"); //Draw arc paths arcs.append("path") .attr("fill", function(d, i) { return color(i); }) .attr("d", arc); //Labels arcs.append("text") .attr("transform", function(d) { return "translate(" + arc.centroid(d) + ")"; }) .attr("text-anchor", "middle") .text(function(d) { return d.value; }); </script> </body>
https://d3js.org/d3.v3.min.js