Get attribute of an array of objects


#1

I am working on a app which should display weight log of the user on a graph.
I’ve declared a model of weight which has three attributes: date, weight, image. In my weight.ts file i would like to read and display on a graph only the weight attribute.

model:
export class Weight {
constructor( public date: Date,
public weight: number,
public imageUrl: string){}
}

weight.ts:

@Component({
selector: ‘page-my-weight’,
templateUrl: ‘my-weight.html’,
})
export class MyWeightPage implements OnInit {
chartOptions: any;
addWeightPage = AddWeightPage;
weights: Weight[] = [];
@ViewChild(‘lineCanvas’) lineCanvas;
lineChart: any;

constructor(public modalCtrl: ModalController,
public navCtrl: NavController,
private weightService: WeightService){

}
getWeight() : number{
return this.weights.values.weight;

}
ionViewDidLoad(){
this.lineChart = new Chart(this.lineCanvas.nativeElement, {

  type: 'line',
  data: {
      datasets: [
          {
              label: "My First dataset",
              fill: false,
              lineTension: 0.1,
              backgroundColor: "rgba(75,192,192,0.4)",
              borderColor: "rgba(75,192,192,1)",
              borderCapStyle: 'butt',
              borderDash: [],
              borderDashOffset: 0.0,
              borderJoinStyle: 'miter',
              pointBorderColor: "rgba(75,192,192,1)",
              pointBackgroundColor: "#fff",
              pointBorderWidth: 1,
              pointHoverRadius: 5,
              pointHoverBackgroundColor: "rgba(75,192,192,1)",
              pointHoverBorderColor: "rgba(220,220,220,1)",
              pointHoverBorderWidth: 2,
              pointRadius: 1,
              pointHitRadius: 10,
              data:     ????????????? WHAT SHALL I WRITE HERE?
              spanGaps: false,
          }
      ]
  }

});

Thanks in advance for help