我認爲我的問題是已知的問題,每次我製作新圖表並將鼠標懸停在畫布上的某些點上時,舊圖表始終閃爍。 Here's one of the threads我跟着嘗試修復它,但似乎沒有任何工作。我試圖重新添加畫布,使用銷燬,清除,如果哪個應該清除它,但沒有。ChartJs鼠標懸停錯誤(顯示以前的圖表)
這裏是我的代碼:
var ctx = document.getElementById('myChart').getContext('2d');
var myChart = new Chart(ctx, {
type: 'line',
data: {
labels: chartjsDate,
datasets: [{
label: 'temp',
data: chartjsTemp,
backgroundColor: "rgba(240,240,240,0.5)"
}]
}
});
我嘗試過,並且代碼之後,甚至if(myChart!=null){myChart.destroy();}
加入myChart.destroy();
,但仍然一無所獲。任何幫助如何解決它將不勝感激。我發現的所有其他線程都很老,他們的解決方案不起作用。
編輯:有些東西,我試過了,沒有用:
var myChart;
if (myChart != undefined || myChart !=null) {
myChart.destroy();
}
如何以及在哪裏聲明瞭您的myChart? – hyperfkcb