简体   繁体   English

Chartjs Donut Chart倒计时动画流畅

[英]Chartjs Doughnut Chart smooth animation in countdown

I am using doughnut chart from Chart.js to show 60 seconds timer chart. 我正在使用Chart.js中的甜甜圈图来显示60秒计时器图。

Gif: https://imgur.com/UmhqzuO Gif: https//imgur.com/UmhqzuO

options = {
    tooltips: {enabled: false},
    cutoutPercentage: 75,
    animation: {duration: 1}
};

data = {
    datasets: [
        {
            data: [this.percentage, 100 - this.percentage],
            backgroundColor: [this.color, this.fillColor]
        },
    ]
};

On every second, I am updating the chart to reflect seconds. 每秒钟,我都会更新图表以反映秒数。 The timer start from 60 seconds and goes to 0. The current animation feels like ticking. 计时器从60秒开始,并变为0。当前动画感觉像是在滴答作响。 I want the animation to look smooth as a sweeping clock instead of ticking. 我希望动画看起来像时钟一样平滑而不是滴答作响。

How can I achieve sweep animation? 如何获得扫掠动画? Since the chart is redrawn after each second, how can I maintain the last position and update from that position? 由于图表是在每秒之后重绘的,我如何保持最后一个位置并从该位置更新?

I achieved this using 我使用了

        const data = this.getDataSet();
        this.doughnut.chart.data.datasets[0].backgroundColor = data.backgroundColor;
        this.doughnut.chart.data.datasets[0].data = data.data;
        this.doughnut.chart.update();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM