4👍
There is no need to literally clear the canvas. But you need to destroy the chartjs object before you reinitialize it. So, it’s like re-creating a chartjs object on the same canvas.
All you need to do is check if the instance already exists before creating the object in drawChart method.
function drawChart(cdiv, ctype){
if(chartx){
chartx.destroy();
}
chartx = new Chart(.....
......
}
- [Chartjs]-Chart.js – Getting data from database using mysql and php
- [Chartjs]-Vue and Chartjs – Running a simple example of vue-chartjs
Source:stackexchange.com