0

I'm using Ng2-charts for drawing pie chart in the angular App.

If I assign this.pieChartData values inside constructor or ngOnInIt, pie chart is rendering properly without any issue.

ngOnInit () { this.pieChartData = [10,20]; } // works fine

But if i assign the values inside the .subscribe method, pie chart color is not rendering.

    this.service.getJiraOpenIssues('22407')
    .subscribe((response)=>{
     this.pieChartData = [10,20];
  });

Please tell me what I'm doing wrong here.

aq2dwe
  • 45
  • 1
  • 1
  • 10

1 Answers1

1

When you are passing data in constructor or in ngOnInit() it will works fine because charts get the data before rendering.

In your case you are passing data in subscribe then chart will not get your data.

You have to tell chart that you have a some new data. For that you have to use .update() method to update your chart's data. That's it.

Then your chart will render new updated data. :)

For detail example code view this example. It may help you.

Sachin Shah
  • 4,503
  • 3
  • 23
  • 50