Chartjs-Chart.js 2.1.2 Bar Chart Animation Issue

0👍

I ended up posting this as a bug on the chart.js GitHub page since I didn’t get any responses here. Following the suggestion from etimberg I changed the drawRegByHourChart function from this:

function drawRegByHourChart(animate) {

            $("#regbyhour").remove();
            $("#regbyhour-container").append('<canvas id="regbyhour"></canvas>');

            var context = $("#regbyhour");
            var chart = new Chart(context, {
                type: 'bar',
                data: barData
                // Need to enable or disable animation here based on animate parameter
            });
        };

To this:

function drawRegByHourChart(animate) {

        $("#regbyhour").remove();
        $("#regbyhour-container").append('<canvas id="regbyhour"></canvas>');

        var context = $("#regbyhour");
        var chart = new Chart(context, {
            type: 'bar',
            data: barData
        });
        if (!animate) {
            chart.update(0);
        }
    };

Leave a comment