Chartjs-Angular 8 and ng2 charts โ€“ Updating labels and data

0๐Ÿ‘

I also encountered this problem when trying to apply translations to the labels I used in the graph. I have read somewhere also here in stackoverlfow that you have to change the reference of the array you are using in the graph.

For your example, you can try

 getLabel(depositParent) {
    let target = this.depositSourceValue[depositParent];
    this.doughnutChartLabels = [...this.doughnutChartLabels, depositParent];
    // this.chart.chart.update();
  }

  getData(depositParent) {
    let data = this.depositSourceAmount[depositParent];
    this.doughnutChartData = [...this.doughnutChartData, depositParent];
    // this.chart.chart.update();
  }

I would also suggest that you use a service that holds an Observable and let this component subscribe to it so that it receives the notification and call the code that updates the graph.

Hope this helps.

Leave a comment