I have a server side script that collects sensor data into a database with multi-threading. On the front-end I have a very simple angular page, where I would like to display these data in graphs. The plan is that I get the active modules that are measuring sensor information on the server side. An example response for that looks like this:
[
{
"id": 1,
"name": "CPU Usage",
"frequency": 5,
"unit": "%"
},
{
"id": 2,
"name": "Memory Usage",
"frequency": 4,
"unit": "GB"
}
]
Then I would like to create two graphs that I can update over the time. This is the code I'm trying to use to set up the graphs:
export class DashboardComponent implements OnInit {
public charts: [];
constructor(private httpClient: HttpClient, private dataService: ApiService) { }
ngOnInit(): void {
this.httpClient.get<any>(this.dataService.baseUrl + '/measurable/active').subscribe({
next: data => {
console.debug(data);
data.forEach(function (item, charts) {
// let charts = [];
document.getElementById('charts').innerHTML
+= '<label>' + item.name + '(' + item.unit + ')' + '</label>'
+ '<canvas id="chart' + item.id + '" style="width:100%; height:200px" width="1262" height="200"></canvas>';
let newCharts = new SmoothieChart();
newCharts.streamTo(document.getElementById('chart' + item.id));
charts.push(newCharts);
});
},
error: error => {
console.error('Could not load any measurable', error.message);
}
})
console.debug(this.charts);
}
}
Unfortunately I'm not very familiar with front-end technologies, so I don't really know how should I do it correctly to make it work. Can someone help me with it, please?