added visualisation

This commit is contained in:
Daniel Ledda
2020-11-05 00:34:57 +01:00
parent b34b0a60d8
commit 8fed9ee0d5

View File

@@ -27,18 +27,21 @@
data: humidity, data: humidity,
borderColor: humidityColor, borderColor: humidityColor,
fill: false, fill: false,
id: 'humidity',
yAxisID: 'y-axis-3', yAxisID: 'y-axis-3',
}, { }, {
label: 'Temperature', label: 'Temperature',
data: temp, data: temp,
borderColor: tempColor, borderColor: tempColor,
fill: false, fill: false,
id: 'temp',
yAxisID: 'y-axis-2', yAxisID: 'y-axis-2',
}, { }, {
label: 'Co2 Concentration', label: 'Co2 Concentration',
data: co2, data: co2,
borderColor: co2Color, borderColor: co2Color,
fill: false, fill: false,
id: 'co2',
yAxisID: 'y-axis-1', yAxisID: 'y-axis-1',
}] }]
}, },
@@ -109,6 +112,22 @@
return {humidity, co2, temp}; return {humidity, co2, temp};
} }
function startFetchTimeout(chart) {
setInterval(async () => {
const newDatum = await fetch("data/1");
const snapshot = (await newDatum.json()).snapshots[0];
chart.data.datasets.forEach(ds => {
if (ds.id === "humidity") {
ds.data.push({x: snapshot.time, y: snapshot.humidity});
} else if (ds.id === "temp") {
ds.data.push({x: snapshot.time, y: snapshot.temp});
} else if (ds.id === "co2") {
ds.data.push({x: snapshot.time, y: snapshot.co2});
}
})
}, 10 * 1000);
}
initChart(); initChart();
</script> </script>