私は D3 を初めて使用し、ドーナツ チャートを持っていますが、各アークの外側にアーク ラベルを取得できません。
http://bl.ocks.org/Guerino1/2295263の紫色のラベルのようなものを取得したいのですが、ドーナツ チャートでは機能しません。
次のコードを使用して各アークのラベルを追加していますが、arc.centroid が期待どおりに機能していないようです。
var arcs = vis.selectAll("g.slice")
arcs.append("svg:text")
.attr("transform", function(d, i) { //set the label's origin to the center of the arc
d.outerRadius = svgOuterRadius + 40; // Set Outer Coordinate
d.innerRadius = svgOuterRadius + 35; // Set Inner Coordinate
return "translate(" + arc.centroid(d) + ")";
})
.attr("text-anchor", "middle") //center the text on it's origin
.style("fill", "Purple")
.style("font", "bold 14px Arial")
.text(function(d, i) { return 'label'+i; }); //get the label from our original
これが私のJSfiddleです:
事前に本当に感謝しています。