D3
OG
Old school D3 from simpler times
All examples
By author
By category
About
bhgray
Full window
Github gist
donut with padding and centroid dots
Built with
blockbuilder.org
<!DOCTYPE html> <head> <meta charset="utf-8"> <script src="https://d3js.org/d3.v4.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 data = [1, 1, 2, 3, 5, 8, 13, 21]; var width = 960, height = 500, radius = height / 2 - 10; var arc = d3.arc() .innerRadius(radius - 40) .outerRadius(radius); var pie = d3.pie() .padAngle(.01); var dot = d3.symbol(); var arcs = pie(data); var color = d3.scaleOrdinal(d3.schemeCategory10); var svg = d3.select("body").append("svg") .attr("width", width) .attr("height", height) .append("g") .attr("transform", "translate(" + width / 2 + "," + height / 2 + ")"); svg.selectAll("path") .data(arcs) .enter().append("path") .style("fill", function(d, i) { return color(i); }) .attr("d", arc); arcs.forEach(function(d, i) { var c = arc.centroid(d); d3.select(d) .append("path") .attr("d", dot) .attr("transform", function(d, i) { var c = arc.centroid(d1); return "translate(" + c[0] + "," + c[1] + ")"; }); }); </script> </body>
https://d3js.org/d3.v4.min.js