D3
OG
Old school D3 from simpler times
All examples
By author
By category
About
mostaphaRoudsari
Full window
Github gist
simple pie chart for comfort
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> // doesn't look d3 fancy but this is all I need for this pie chart var color = ['#b2182b','#ef8a62','#fddbc7','#f7f7f7','#d1e5f0','#67a9cf','#2166ac']; var width = 90; var svg = d3.select("body").append("svg") .attr("width", width) .attr("height", width) // add pie chart var place_holder_data = [10, 10, 10, 10, 10, 10, 10]; var radius = width /2 ; var pie = d3.layout.pie()(place_holder_data); var arc = d3.svg.arc() .innerRadius(radius / 2) .outerRadius(radius - 5); var pp = svg.append("g") .attr("class", "pie") .attr("transform", "translate(" + width / 2 +", " + width / 2 +")"); pp.selectAll("path") .attr("class", "pie") .data(pie).enter() .append("path") .attr("fill", function(d, i) { return color[i]; }) .attr("stroke", "black") .attr("d", arc); function update_pie(new_data) { // in my case number of values are always the same var pie = d3.layout.pie().value(function(d) { return d; })(new_data); path = d3.select(".pie").selectAll("path").data(pie); // Compute the new angles path.attr("d", arc); // redrawing the path } </script> </body>
https://d3js.org/d3.v3.min.js