I developed pie charts as follows chartjs V2.6.0. It works fine whenever I search with new data in same pie chart it shows previous data when on hover. I tried with $('#canvas').remove();
method, but it's not working.
var color = [];
var label = [];
var datas = [];
var odata = 1;
for (i = 0; i < result.length; i++) {
label.push(result[i].label);
color.push(result[i].color);
datas.push(result[i].value1);
}
var config = {
type: 'pie',
data: {
labels: label,
datasets: [{
backgroundColor: color,
data: datas
}]
},
options: {
responsive: true,
legend: {
display: false
},
tooltips: {
enabled: true,
},
onClick: graphClickEvent
}
};
var ctx = document.getElementById("state-area").getContext("2d");
new Chart(ctx, config);
function graphClickEvent(event, array) {
console.log(event);
console.log(array);
}
I Used just removed previous canvas and added new canvas. it works fine.