Array Data to Chart

17 views
Skip to first unread message

Martin Kuenz

unread,
Oct 21, 2020, 1:26:31 PM10/21/20
to Angular and AngularJS discussion

I have a problem. I have a list of data that I output grouped. Now I want to output the values e.g. erzeugenGes to a barchart. Chart modules itself works. Fail only at the grouped data for evaluation. Enclosed my code and list

1,2,3,4,5,6,7,8,9,10,11,12 are the Month for the ChartLabels


1: [{…}] 2: [{…}] 3: [{…}] 4: [{…}] 5: [{…}] 6: [{…}] 7: [{…}] 8: [{…}] 9: Array(1) 0: {jahr: 2020, monat: 9, erzeugungGes: 901.04, verbrauchGes: 952.22, eigenverbrauch: 515.24, …} length: 1 __proto__: Array(0) 10: Array(2) 0: bezogen: 252.18 eigenverbrauch: 201.62 eingespeist: 140.94 erzeugungGes: 342.53 jahr: 2019 monat: 10 verbrauchGes: 453.75 __proto__: Object 1: bezogen: 232.07 eigenverbrauch: 174.13 eingespeist: 102.37 erzeugungGes: 276.48 jahr: 2020 monat: 10 verbrauchGes: 406.19 __proto__: Object length: 2 __proto__: Array(0) 11: Array(1) 0: {jahr: 2019, monat: 11, erzeugungGes: 291.87, verbrauchGes: 761.16, eigenverbrauch: 238.38, …} length: 1 __proto__: Array(0) 12: [{…}]  


getData() { this.ds.getAuswertungJahr().subscribe(res => { this.daten = res; this.data = this.daten.reduce((r, a) => { console.log("a", a); console.log('r', r); r[a.monat] = [...r[a.monat] || [], a]; return r; }, {}); console.log("group", this.data); this.barChartData[0].data = []; for (let i = 0; i < this.data.lenght; i++) { this.barChartData[0].data.push(this.data[i]); } })  



Reply all
Reply to author
Forward
0 new messages