D3
OG
Old school D3 from simpler times
All examples
By author
By category
About
adgramigna
Full window
Github gist
Women Table1
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; } .arc text { font: 7px tahoma; text-anchor: middle; } .arc path { stroke: #fff; } </style> </head> <body> <script> var width = 960, height = 500, radius = Math.min(width, height) / 2; var color = d3.scaleOrdinal() .range(["#98abc5", "#8a89a6", "#7b6888", "#6b486b", "#a05d56", "#d0743c", "#ff8c00"]); var arc = d3.arc() .outerRadius(radius - 10) .innerRadius(0); var labelArc = d3.arc() .outerRadius(radius - 40) .innerRadius(radius - 40); var pie = d3.pie() .sort(null) .value(function(d) { return d.y; }); var svg = d3.select("body").append("svg") .attr("width", width) .attr("height", height) .append("g") .attr("transform", "translate(" + width / 2 + "," + height / 2 + ")"); d3.csv("Table_1F.csv", type, function(error, data) { if (error) throw error; var total = d3.sum(data, function(d){return parseFloat(d.y);}) var g = svg.selectAll(".arc") .data(pie(data)) .enter().append("g") .attr("class", "arc"); g.append("path") .attr("d", arc) .style("fill", function(d) { return color(d.data.y) }); g.append("text") .attr("transform", function(d) { return "translate(" + labelArc.centroid(d) + ")"; }) .attr("dy", ".35em") .text(function(d) { return d.data.x+d3.format(".2f")(d.data.y / total * 100) + "%" }); svg.append("text") .attr("x", -260) .attr("y", -50) .attr("text-anchor", "end") .style("font-size", "20px") // .style("text-decoration", "underline") .text("Percent of Women Whose"); svg.append("text") .attr("x", -250) .attr("y", -30) .attr("text-anchor", "end") .style("font-size", "20px") // .style("text-decoration", "underline") .text("Highest Level of Education"); svg.append("text") .attr("x", -280) .attr("y", -10) .attr("text-anchor", "end") .style("font-size", "20px") .text("Is a Bachelor's Degree"); svg.append("text") .attr("x", -350) .attr("y", 10) .attr("text-anchor", "end") .style("font-size", "20px") // .style("text-decoration", "underline") .text("By Age"); }); function type(d) { d.y = +d.y; return d; } </script> </body>
https://d3js.org/d3.v4.min.js