最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - chart.js on animation end callback - Stack Overflow

programmeradmin3浏览0评论

Does the library chart.js support any sort of callbacks on specific events? I'm mostly interested in 'on animation end' event, but would be nice to know any other events if they're supported.
If this is not an option, do you know any workarounds? I'm using jQuery and vue.js and I just need to show some additional text on the page (pletely outside of the chart itself) when chart.js finishes the animation of the chart.

Does the library chart.js support any sort of callbacks on specific events? I'm mostly interested in 'on animation end' event, but would be nice to know any other events if they're supported.
If this is not an option, do you know any workarounds? I'm using jQuery and vue.js and I just need to show some additional text on the page (pletely outside of the chart itself) when chart.js finishes the animation of the chart.

Share Improve this question asked Jun 27, 2015 at 2:35 vitrvitr 7,1348 gold badges32 silver badges52 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 8

For Chart.Js 2.6.0

options: {
    cutoutPercentage: 90,
    animation: {
        duration: 2000,
        onProgress: function(animation) {
            $progress.attr({
                value: animation.animationObject.currentStep / animation.animationObject.numSteps,
            });
        },
        onComplete: function(animation) {
            alert('onAnimationComplete')
        }
    }
},

See this codepen https://codepen.io/shivabhusal/pen/XaZQaW

There is an onAnimationComplete option you can specify to run stuff once the animation pletes. See this section of the documentation.

Example

var ctx = document.getElementById("chart").getContext("2d");
var myLine1 = new Chart(ctx).Line(lineChartData1, {
    onAnimationComplete: function() {
        alert('animation plete')
    }
});

Fiddle - http://jsfiddle/4vo72rLd/

发布评论

评论列表(0)

  1. 暂无评论