Database data not displayed with ng2-charts library

Viewed 19

I have a problem with the ng2-charts library. I have an api that returns an array

[
    {
        "zona": "Lujan",
        "cantidad": 27
    },
    {
        "zona": "Villa Bosch",
        "cantidad": 1
    }
]

I want to show this data in a graph made in angular like this: enter image description here

for that create a service in angular that returns the data correctly. Then in an app.component.ts I call that service in the following function. In this function I store the data in a variable

  getGraphics() {
return this.graficosService.getGraphics().subscribe(response => {
  const datos = response as GraphicsData[];
  return datos.forEach(propiedad => {
    this.zona = propiedad.zona;
    this.cantidad = propiedad.cantidad;
    console.log(this.zona, this.cantidad);
  });
});

}

I suppose that the function that I show below is the one that shows the data on the screen. In the data I want the quantity to appear and in the years I want the zones to appear

 public barChartData: ChartData<'bar'> = {
labels: ['2006', '2007', '2008', '2009'],
datasets: [
  { data: [65, 59, 80, 81, 56, 55, 40], label: 'Zona' },
] };

thanks for your help!!!!

0 Answers
Related