[Chartjs]-Chart JS dynamic chart

6👍

Try this:

Before binding data , remove the canvas too 😉

HTML:

<div id="DivChartContainer"></div>

SCRIPT:

        $('#DivChartContainer').empty();
        $('#DivChartContainer').append('<canvas id="canvas"></canvas>');
        var ctx = document.getElementById("canvas").getContext("2d");
        var myLineChart = new Chart(ctx).Bar(barChartData, {
            responsive: true,
            barValueSpacing: 10,
            barStrokeWidth: 0,
            scaleShowLabels: true,
            scaleShowGridLines: true,
            scaleGridLineColor: "rgba(0,0,0,.05)",
            scaleGridLineWidth: 1,
        });

Issue Solved !!

2👍

destroy() works fine for me, check this code.

 if (window.myDoughnut)
     window.myDoughnut.destroy();

 var ctx = $elm.getContext("2d");
 window.myDoughnut = new Chart(ctx).DoughnutAlt(value, {showScale: true, scaleShowLabels: true, animation: false});

1👍

I’ve had similar issues with .clear() and .destroy()

What worked for me:

completely remove and replace the <canvas> element

Leave a comment