D3
OG
Old school D3 from simpler times
All examples
By author
By category
About
kalmdown
Full window
Github gist
Learning the ropes
Built with
blockbuilder.org
<!DOCTYPE html> <meta charset="utf-8"> <svg width="960" height="960" font-family="helvetica neue" font-size="10"</svg> <script src="https://d3js.org/d3.v4.min.js"></script> <script src="d3-scale-radial.js"></script> <style> body { margin:0;position:fixed;top:0;right:0;bottom:0;left:0; } </style> <script> var svg = d3.select("svg"), width = +svg.attr("width"), height = +svg.attr("height"), innerRadius = 180, outerRadius = Math.min(width, height) / 2, g = svg.append("g").attr("transform", "translate(" + width / 2 + "," + height / 2 + ")"); var x = d3.scaleBand() .range([0, 2 * Math.PI]) .align(0); var y = d3.scaleRadial() .range([innerRadius, outerRadius]); var z = d3.scaleOrdinal() .range(["#98abc5", "#8a89a6", "#7b6888", "#6b486b", "#a05d56", "#d0743c", "#ff8c00"]); d3.csv("FauxData.csv", function(d, i, columns) { for (i = 1, t = 0; i < columns.length; ++i) t += d[columns[i]] = +d[columns[i]]; d.total = t; return d; },function(error, data) { if (error) throw error; x.domain(data.map(function(d) { return d.State; })); y.domain([0, d3.max(data, function(d) { return d.total; })]); z.domain(data.columns.slice(1)); g.append("g") .selectAll("g") .data(d3.stack().keys(data.columns.slice(1))(data)) .enter().append("g") .attr("fill", function(d) { return z(d.key); }) .selectAll("path") .data(function(d) { return d; }) .enter().append("path") .attr("d", d3.arc() .innerRadius(function(d) { return y(d[0]); }) .outerRadius(function(d) { return y(d[1]); }) .startAngle(function(d) { return x(d.data.State); }) .endAngle(function(d) { return x(d.data.State) + x.bandwidth(); }) .padAngle(0.01) .padRadius(innerRadius)); </script>
https://d3js.org/d3.v4.min.js