D3
OG
Old school D3 from simpler times
All examples
By author
By category
About
aaizemberg
Full window
Github gist
square pie chart ( d3.js )
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <script src="https://cdnjs.cloudflare.com/ajax/libs/d3/3.5.6/d3.min.js"></script> </head> <body> <script> var width = 200, height = 200, radius = Math.min(width, height) / 1.34; // var width = 200, height = 200, radius = Math.min(width, height) / 2; var c10 = d3.scale.category10(); var arc = d3.svg.arc() .outerRadius(radius - 10) .innerRadius(0); var data = [ ["de",1968], ["la",1407], ["el",1246], ["en",1066], ["a",1044], ["y",687] /* ["un",580], ["del",504], ["por",471], ["los",437] */ ]; var pie = d3.layout.pie() .sort(null) .value(function(d) { return d[1]; }); var svg = d3.select("body").append("svg") .attr("width", width) .attr("height", height) .append("g") .attr("transform", "translate(" + width / 2 + "," + height / 2 + ")"); var g = svg.selectAll(".arc") .data(pie(data)) .enter().append("g") .attr("class", "arc"); g.append("path") .attr("d", arc) .attr("stroke", "#fff") .style("fill", function(d,i) { return c10(i); }); g.append("text") .attr("transform", function(d) { return "translate(" + arc.centroid(d) + ")"; }) .attr("dy", ".35em") .style("text-anchor", "middle") .attr("fill","white") .text( function(d) {return d.data[0];} ); </script> </body> </html>
https://cdnjs.cloudflare.com/ajax/libs/d3/3.5.6/d3.min.js