Chartjs-Chartjs Bar Chart showing old data when hovering when use of ajax

0👍

i had a similar experience. so i am using this way which is destroying previous chart before draw new one.
my code down below

var canvasContainer = canvasItem.parent();
var canvasHtml = '<canvas id="'+canvasItem.attr('id')+'"><canvas>';
canvasItem.remove();
$(canvasContainer).append(canvasHtml);

…wirte your chart options like

var options = {
    title:{},
    scalses:{}
}

after you write the options you wanna use in your chart
then

var ctx = document.getElementById(canvasItem.attr('id')).getContext('2d');
var Chart = new window.Chart(ctx, {
        data:{
        labels:chartdata.date,
        datasets:chartdata.datasets,
        },
        options : options
});

it works fine with me

0👍

This is work for me Change the chart to global by making it window (Change the declaration) Like var lineChart To window.lineChart

For Destroy Chart before Declaire

       if (window.lineChart){

             window.lineChart.destroy();  

           }
      window.lineChart = new Chart(ctx, config);

Hope Help

Leave a comment