Chartjs-Charts.js chart showing old data on hover

0👍

You correctly defined chart_day globally and even commented it as follows:

global variables – so that chartjs doesn’t show old data on hover

The problem however lies in your dayChart function. Instead of using the globally defined chart_day variable, you defined an identically named variable in the local scope of the function.

The solution would be to replace the following code block:

var chart_day = new Chart (ctx_day, config)
if (chart_day) {
    chart_day.destroy();
    chart_day = new Chart (ctx_day, config);
    chart_day.update();
} 

…with this one:

if (chart_day) {
    chart_day.destroy();
}
chart_day = new Chart (ctx_day, config);

Leave a comment