Charts.js listing data from a BD (ionic 3)

0

Good afternoon everyone, I'm studying the ionic and would like to represent some data that is in a DB in my chart. I made the list via api of php and the values are arriving all right (I even used ngfor to list them), but I do not know how to make the data from bd into an array. Here are the codes: (List in .html)

 <ion-item-sliding *ngFor="let produto of mesa">
<ion-item >
  <ion-row>
      <ion-col col-8>
          {{produto.potencia_atual}}  
      </ion-col>
  </ion-row>


</ion-item>
</ion-item-sliding>

page.ts

 grafico(){
  this.consumoProvider.grafico()
  .then(data => {
    this.mesa  = data;

  });
}

page.ts in the part of the label representation:

{
    label: 'Meu terceiro Dataset',
    fill: false,
    lineTension: 0.1,
    backgroundColor: 'rgb(255, 0, 0)',
    borderColor: 'rgb(255, 00, 00)',
    borderCapStyle: 'butt',
    borderJoinStyle: 'miter',
    pointRadius: 1,
    pointHitRadius: 10,
    data: (????),
    scanGaps: false,
  }
]
}

Where "(????)" would be the name of the array variable.

    
asked by anonymous 27.07.2018 / 19:32

1 answer

0

To do this select in the table variable you can use map to get an array only with the current_potential field and use it in the configuration of your chart.

this.terceiroDataset = this.mesa.map(x=>x.potencia_atual);
    
27.07.2018 / 20:32