0
D3을 처음 사용하고 도넛 차트를 얻었지만 각 호 바깥에 호 라벨을 붙일 수는 없습니다.D3 pie (도넛 형) 각 아크 바깥의 차트 레이블
보라색 라벨을 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
Here 내 JSfiddle입니다.
정말 고마워요. 멋지군요. 한가지 더 물어봐도 될까요? d.outerRadius = <내 외부 반경> + 50;을 추가하면서 각 호가 각 호의 바깥에 있도록하고 싶었습니다. d.innerRadius = <내 외부 반경> +45; arc.centroid (d)가 도움이되지 않기 전에. 각 호의 바깥쪽에 각 라벨 위치를 어떻게 얻을 수 있는지 알고 있습니까? – user2975436
[이 질문] (http://stackoverflow.com/questions/8053424/label-outside-arc-pie-chart-d3-js) 도움이됩니다. –
http://stackoverflow.com/a/12543354/2031033 another good one –