How do I clockwise animate Pie Chart onLoad in SVG

旧街凉风 提交于 2020-01-05 04:09:12

问题


I am stuck with pie chart which should animate clockwise onLoad. Here, is my pie chart fiddle

I need this animation to work with brezier curve paths, for instance,

<path d="M 276 63.03 C 329.93 63.03 381.86 78.24 421.4 105.63 L 276 222.79 M 276 63.03" />

I am also aware that, it can be achieved using snap.svg library but is unable workout in this case.

Any help is appreciated.

Thanks in advance!


回答1:


You can use a nested animate and change some attribute with a progressive delay.

In this example I placed the stroke g inside the fill g for each slice, and added an animate element inside, each animation starting 0.5s. I animated the opacity attribute (so I added an opacity="0" attribute for each element; you can replace it for another attribute). This is the second slice:

<g id="pieFillSection2" opacity="0" style="fill: yellow;fill-opacity: 1.0; stroke: none" transform="matrix(1,0,0,1,0,0)" >
    <animate attributeName="opacity" from="0" to="1"
             begin="0.5s" dur="1s" fill="freeze"/>
    <path d="M 421.4 105.63 C 483.64 148.74 505.87 215.26 478.05 275.16 C 450.23 335.05 377.64 377 293.04 382.05 L 276 222.79 M 421.4 105.63" />
    <g class="pieStroke" id="pieStrokeSection2" style="stroke-width: 1.0;stroke: rgb(128,128,128);stroke-opacity: 1.0; fill: none" transform="matrix(1,0,0,1,0,0)" >
        <path d="M 421.4 105.63 C 483.64 148.74 505.87 215.26 478.05 275.16 C 450.23 335.05 377.64 377 293.04 382.05 L 276 222.79 M 421.4 105.63" />
    </g>
</g>

Check the updated JSFiddle.



来源:https://stackoverflow.com/questions/22863758/how-do-i-clockwise-animate-pie-chart-onload-in-svg

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!