Label outside arc (Pie chart) d3.js
问题 I'm new to d3.js and I"m trying to make a Pie-chart with it. I have only one problem: I can't get my labels outside my arcs... The labels are positioned with arc.centroid arcs.append("svg:text") .attr("transform", function(d) { return "translate(" + arc.centroid(d) + ")"; }) .attr("text-anchor", "middle") Who can help me with this? 回答1: I can solve that problem - with trigonometry :). See fiddle: http://jsfiddle.net/nrabinowitz/GQDUS/ Basically, calling arc.centroid(d) returns an [x,y] array.