[Chartjs]-How to reload a jQuery element when a button is pressed

1๐Ÿ‘

โœ…

You can destroy it first like so:

<canvas id="graph"></canvas>

<script>
    let myChart;

    $("#button").click(function() {
        if(Chart.getChart(myChart)) {
          myChart.destroy();
        }

        let ctx = $("#graph");
        myChart = new Chart(ctx, {/* My nice graph. */});
    });
</script>

Leave a comment