I have created a line chart with SVG (polygon points) that I would like animated.
I would like the points to all start animating from the X axis, and when finished animating, the result to look like the following image.
It seems there is no simple way to achieve this, with the googling I have done. Any tips would be most appreciated, thanks.
How it create SVG Animations: Select the Frame you want to animate and click on Enable SVG Export. Select a node within that Frame to set up animations such as X Position, Y Position, Scale, Rotation and Opacity. Use the built-in live-preview to tweak your animations until you're happy with the result.
SVG supports the ability to change vector graphics over time, to create animated effects. SVG content can be animated in the following ways: Using SVG's animation elements [svg-animation]. SVG document fragments can describe time-based modifications to the document's elements.
One of the most common reasons why the SVG animation doesn't work is the use of <img> tags to add the SVG. The SVG might be visible on the website, but the animation will not start. You can easily fix this by replacing all <img> tags with an <object> tag.
What do you mean by "animating from the X axis" exactly? Do you mean start flat and grow upwards to this shape?
If so, it is actually very easy.
<svg viewBox="0 0 2040 352">
<defs>
</defs>
<polygon points="" fill="red">
<animate attributeName="points" dur="1s" fill="freeze"
from="0,352, 550,352, 1240,352, 1592,352, 1880,352, 2040,352,
2040,352,0,352"
to="0,292, 550,232, 1240,258, 1592,158, 1880,168, 2040,0,
2040,352,0,352"/>
</polygon>
</svg>
This example uses vanilla SVG SMIL animations. You can also use one of a number of SVG graphing or animation libraries.
This effect can be easily achieved with transform:scaley
keyframe animation:
(javascript code in followind snippet is only for generating random svg polygon)
let n = 5, w = innerWidth - 20, h = innerHeight - 20;
let pts = Array(n).fill(0).map((_, i) => [(1+i)*(w/(n+1)), -Math.random()* h]);
document.body.innerHTML += `<svg width=${w} height=${h} viewbox=0,${-h},${w},${h} >
<polygon points=0,0,${pts},${w},0 /></svg>`;
@keyframes grow {
0% {transform: scaley(0)}
100% {transform: scaley(1)}
}
polygon {
fill: #e45;
animation: grow 0.5s forwards;
}
I have done something in the past, this was however with a single control point of a SVG Bezier curve. However I think you can apply the same principle. I think you need to do the following steps
animate example
$({ n: 0 }).animate({ n: 40}, {
duration: 1000,
step: function(calculatedYValue, fx) {
//update graphs with calculatedYValue
console.log(parseInt(calculatedYValue), 10);
}
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With