繁体   English   中英

如何根据数组数据更新d3甜甜圈中的文本标签

[英]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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM