Adding new segments to a Animated Pie Chart in D3.js

寵の児 提交于 2019-12-04 17:05:00

To get the transition to work smoothly, you need to add the code that you're using initially to your update function as well. Working jsfiddle here.

And some code to make SO happy -- this is what needs to be in the update function as well:

.enter()
.append("path")
.attr("stroke", "white")
.attr("stroke-width", 0.8)
.attr("fill", function(d, i) { return color(i); })
.attr("d", arc)
.each(function(d) { return this.current = d; });

.enter()
.append("text")
.attr("class", "arcLabel")
.attr("transform", function(d) { return "translate(" + (arc.centroid(d)) + ")"; })
.attr("text-anchor", "middle")
.style("fill-opacity", function(d) {
  if (d.value === 0) { return 1e-6; }
  else { return 1; }
})
.text(function(d) { return d.data.label; });
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!