Chart.js / ng2-chart更新后不会重绘

时间:2019-06-26 10:38:10

标签: chart.js ng2-charts

Stackblitz url动态将数据集添加到现有图表。     当前,Chart有两个数据集,显示两个条形,一个是新的,另一个是重复的。     单击后,另一个数据集已添加到现有数据集对象。在控制台中检查值时,它给出/打印出

Refer https://ng2-chart-example-2t7den.stackblitz.io 


export class AppComponent implements AfterViewInit {
    @ViewChild(BaseChartDirective) chart: any;

      ngAfterViewInit() {
    this.updateDataset();`data`
}

  public chartData: BarChartDataset[] =

    updateDataset(){
        let marketVal =  { data: [0 , 0, 30 , 100], label: 'New Data'}  
           //  this.chartData.pop();

           // Added chart data set dynamically upon click. Upon click another dataset has been added to the existing dataset object. While checking the value in cosnole it gives/print the


             this.chartData.push(marketVal);
             console.log(this.chartData);
             console.log(this.chart);
             this.chart.chart.update();
 //updated chart

}
}

0 个答案:

没有答案