ng2-charts update labels and data

前端 未结 12 1056
长发绾君心
长发绾君心 2020-12-03 01:25

I\'m trying to create dynamically a chart using ng2-chart, I get information from an angular 2 service, when I change only labels of chart it works and when I change data on

12条回答
  •  [愿得一人]
    2020-12-03 01:52

    Using BaseChartDirective i did chart update and it served the purpose. Sample below:

    import { BaseChartDirective } from 'ng2-charts/ng2-charts';
    

    inside the class add as below

    @ViewChild(BaseChartDirective) chart: BaseChartDirective;
    

    While you have the values to be changed, add as below

     this.chart.ngOnChanges({});
    

提交回复
热议问题