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

Asked

Viewed 93 times

0

Good afternoon everyone, I am studying Ionic and would like to represent some data that is in a comic in my chart. I made the list via php api and the values are all coming right(I even used ngfor to list them), but I don’t know how to turn the bd data into an array. Follow 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 label representation part:

{
    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,
  }
]
}

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

  • Just to be clear, the select of the api is this: select current potentialfrom current consumo_current.

1 answer

0


to make this select in the table variable you can use map to get an array only with the current potenta_field and use it in your chart configuration.

this.terceiroDataset = this.mesa.map(x=>x.potencia_atual);
  • It worked man! Thank you so much!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.