Browse Source

feat: Live updates and X-Axis breaking

master
Konstantinos Kamaropoulos 5 years ago
parent
commit
8cf1335816
  1. 44
      src/app/chart/chart.component.ts

44
src/app/chart/chart.component.ts

@ -55,9 +55,11 @@ export class ChartComponent implements OnInit {
title: { title: {
text: 'Sensor Readings' text: 'Sensor Readings'
}, },
// axisX: { axisX: {
// title: "chart updates every second" scaleBreaks: {
// }, autoCalculate: true
}
},
toolTip: { toolTip: {
shared: true shared: true
}, },
@ -89,23 +91,25 @@ export class ChartComponent implements OnInit {
} }
}); });
this.chart.render(); this.chart.render();
// this.sub = interval(1000).subscribe(async val => {
// let data = await this.logsService.getUpdates();
// let mq2: any = data.map((log: any) => {
// return log['sensorReadings']['MQ2'];
// });
// let j = i;
// mq2.forEach((value: any) => {
// this.dataPoints["MQ2"].push({ x: ++j, y: parseInt(value) });
// dpsLength++;
// });
// i = j;
// // if (dataPoints.length > 20 ) { this.sub = interval(1000).subscribe(async val => {
// // dataPoints.shift(); let data = await this.logsService.getUpdates();
// // } let sensorReadings: any = data.map(log => {
// this.chart.render(); let d = log['sensorReadings'];
// }); d['time'] = log['createdAt'];
return d;
});
sensorReadings.forEach((element: any) => {
for (const key in element) {
if (element.hasOwnProperty(key) && key != 'time') {
const value = element[key];
this.dataPoints[key].push({ x: new Date(element['time']), y: parseInt(value) });
dpsLength = this.dataPoints.length;
}
}
dpsLength++;
});
this.chart.render();
});
} }
} }

Loading…
Cancel
Save