SVG를 이용한 line-chart animation 만들기
.line {
stroke-dasharray: 1100;
stroke-dashoffset: 0;
animation: dash 3s linear alternate;
}
@keyframes dash {
0% { stroke-dashoffset: 1100; }
100% { stroke-dashoffset: 0; }
}
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" id="visual" viewBox="0 0 900 600" width="900" height="600" version="1.1" style="border: 1px solid #000;"><rect x="0" y="0" width="900" height="600" fill="#fff"/>
<path class="line" d="M0 482L25 500C50 518 100 554 150 519.7C200 485.3 250 380.7 300 371.2C350 361.7 400 447.3 450 466.7C500 486 550 439 600 436.2C650 433.3 700 474.7 750 457.2C800 439.7 850 363.3 875 325.2L900 287" fill="none" stroke-linecap="round" stroke-linejoin="miter" stroke="#0066FF" stroke-width="18"/>
</svg>
<script type="text/javascript">
path = document.querySelector('path').getTotalLength();
console.log(path);
//path의 길이를 console에서 확인
//실행하면 1103.0550537109375 의 길이를 확인할 수 있다
</script>
svg 코드 작성 후
** 현재 코드는 html 안에 width, stroke(color), fill 등이 포함되어 있어 별도로 css를 추가하지 않았다.
👏👏👏 보고 따라 해봤는데, 설명도 쉽고 금방 되었어요! 감사합니다!!