Dynamically updated ng2-charts

ulou picture ulou · Aug 22, 2016 · Viewed 24.1k times · Source

Is it possible to update any chart from ng2-charts dynamically? I know there are other libraries like angular2-highcharts, but I would like to handle it using ng2-charts. Main question is how can I redraw chart, after button click? I can resize window and data will be updated, so it have to be any option to do it manually.

https://plnkr.co/edit/fXQTIjONhzeMDYmAWTe1?p=preview

Answer

Standaa - Monica side picture Standaa - Monica side · Oct 29, 2016

A good way is to get a grip on the chart itself in order to redraw it using the API :

export class MyClass {
 @ViewChild( BaseChartDirective ) chart: BaseChartDirective;

  private updateChart(){
   this.chart.ngOnChanges({});
  }

}