How to clear a chart from a canvas so that hover events cannot be triggered?

后端 未结 21 1813
不思量自难忘°
不思量自难忘° 2020-11-28 20:07

I\'m using Chartjs to display a Line Chart and this works fine:

// get line chart canvas
var targetCanvas = document.getElementById(\'chartCanvas\').getConte         


        
21条回答
  •  伪装坚强ぢ
    2020-11-28 20:46

    I have faced the same problem few hours ago.

    The ".clear()" method actually clears the canvas, but (evidently) it leaves the object alive and reactive.

    Reading carefully the official documentation, in the "Advanced usage" section, I have noticed the method ".destroy()", described as follows:

    "Use this to destroy any chart instances that are created. This will clean up any references stored to the chart object within Chart.js, along with any associated event listeners attached by Chart.js."

    It actually does what it claims and it has worked fine for me, I suggest you to give it a try.

提交回复
热议问题