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
- Chartjs-Custom tooltip callback on one dataset (chartjs v 2.5)
- Chartjs-How to differentiate the data of one topic or another coming from Mercure hub if the client is suscribed to two topics
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
Source:stackexchange.com