Chartjs-Angular6 and ng2-charts does not display any charts when i fill data from webservice

0👍

The chart itself seems fine, so I guess the problem is the way you try to fill your arrays.

You have checked the content of countriestData and countriesLabel?

You didn’t show what exactly chartService.getCountryGroupBy() returns, but I guess it’s only the response body of the request, so you’ll probably have to change your code to

this.chartService.getCountryGroupBy().subscribe(data => {

    data.forEach(country => {
      this.countriestData.push(country.count);
      this.countriesLabel.push(country.country);
    });

});

0👍

Try this:

public countriesLabel: string[] = [{ data: [] }];
public countriestData: number[] = [{ data: [] }];

or

public countriesLabel: any[] = [{ data: [] }];
public countriestData: any[] = [{ data: [] }];

I could solve my similar problem by changing the definition of my data to this format.

Leave a comment