0π
I suggest to disable chart animation, and instance the chart and canvas inside a variable and then try to destroy chart and make undefined the canvas (to free memory), aftwerwards create a new chart.
0π
var chart_holder, canvas_holder = null;
function drawChart(){
try{
chart_holder.destroy()
canvas_holder = undefined;
}catch(e){}
canvas_holder = document.createElement("canvas");
$('#divelement').empty().append(canvas_holder);
chart_holder = new Chart(canvas_holder, {
type: 'bar',
data: data,
options: {...}
})
}
- [Chartjs]-How to set default colour for bars in Chart.js
- [Chartjs]-ChartJS New Lines '\n' in X axis Labels or Displaying More Information Around Chart or Tooltip with ChartJS V2
0π
You have to instance the chart in a variable and update the variable. You can see it in my jsbin.
You can find more information about updating charts in the docs.
Important part:
let chart = new Chart(document.getElementById("chart"), { // can be any variable name
type: 'line',
data: data,
options: options
});
function addDataButton(){
addData()
chart.update() // chartInstance.update()
}
Source:stackexchange.com