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

后端 未结 21 1810
不思量自难忘°
不思量自难忘° 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:58

    If you are using chart.js in an Angular project with Typescript, the you can try the following;

    Import the library:
        import { Chart } from 'chart.js';
    
    In your Component Class declare the variable and define a method:
    
      chart: Chart;
    
      drawGraph(): void {
        if (this.chart) {
          this.chart.destroy();
        }
    
        this.chart = new Chart('myChart', {
           .........
        });
      }
    
    
    In HTML Template:
    
    

提交回复
热议问题