Animating D3 donut chart on load

前端 未结 1 1128
深忆病人
深忆病人 2021-02-01 19:16

I have a donut chart with five different arcs inside of it. The data will not be updated but I want to have a transition of the whole graph being drawn as a circle when the page

相关标签:
1条回答
  • 2021-02-01 19:47

    You can do this with an attribute tween:

    .attrTween('d', function(d) {
       var i = d3.interpolate(d.startAngle+0.1, d.endAngle);
       return function(t) {
           d.endAngle = i(t);
         return arc(d);
       }
    });
    

    This animates the segment from start to end angle. To do this across the entire circle, you can use delayed transitions:

    .transition().delay(function(d, i) { return i * 500; }).duration(500)
    

    Complete example here. You can adjust start segment, duration, etc to your liking.

    0 讨论(0)
提交回复
热议问题