[英]How can I update text-label in d3 donut according with my array's data
我試圖增加的百分比,而不是標簽, 在這里用數組根據。 每次甜甜圈過渡后,我都需要更新標簽。 如果我只插入.text(function (d) { return d.data.value;});
它只顯示第二個數組的值,並且沒有變化。 我該如何解決?
PS:我在這里看到了類似的問題-但我無法將他們的解決方案用於我的甜甜圈。
在過渡結束時更新標簽:
slice
.transition().duration(1000)
.each("end", function(d,i){
d3.selectAll('.labels text')
.text(function(d) {
return (((d.endAngle - d.startAngle) / (2 * Math.PI)) * 100).toFixed(0) + '%';
})
})
.attrTween("d", function(d) {
this._current = this._current || d;
var interpolate = d3.interpolate(this._current, d);
this._current = interpolate(0);
return function(t) {
return arc(interpolate(t));
};
});
更新示例 。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.