Chartjs-OnAnimationComplete is executed before animation is done

1👍

Simple. Don’t call the done function.

options: {
    responsive: false,
    legend: {
        display: false,
    },
    onAnimationComplete: done // <--- no parentheses!
}

1👍

I think that’s happening because your function is being called directly when the script is executed in the browser. That’s not a callback. You can try this:

var done = function () {
    var url = document.getElementById("myChart").toDataURL();
    // alert(url);
    $("#foobar").attr("src", url);
}

And further:

//Notice how I am using the variable instead of calling the function.
onAnimationComplete: done

Leave a comment