aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarcin Zelent <zelent.marcin@gmail.com>2018-03-16 17:48:44 +0100
committerMarcin Zelent <zelent.marcin@gmail.com>2018-03-16 17:48:44 +0100
commited01011dfb563e7d8ab13b6a0718eed7bf857880 (patch)
tree104a22a75d287d0607668eea3177eec626ab3f80 /pollutometer-php/web/js/LastWeekDataChart.js
parent1d24e941dc7d9da10c9045203ae18f5234c774f5 (diff)
Moved PHP website to separate directory.
Diffstat (limited to 'pollutometer-php/web/js/LastWeekDataChart.js')
-rw-r--r--pollutometer-php/web/js/LastWeekDataChart.js63
1 files changed, 63 insertions, 0 deletions
diff --git a/pollutometer-php/web/js/LastWeekDataChart.js b/pollutometer-php/web/js/LastWeekDataChart.js
new file mode 100644
index 0000000..b5e3976
--- /dev/null
+++ b/pollutometer-php/web/js/LastWeekDataChart.js
@@ -0,0 +1,63 @@
+var gasReading = {
+ Co: [],
+ No: [],
+ So: []
+};
+
+var canvas = document.querySelector('#ctx');
+var ctx = canvas.getContext('2d');
+
+var datasets = [{
+ label: "Co",
+ borderColor: "rgb(5, 0, 0)",
+ fill: false,
+ data: []
+}, {
+ label: "No",
+ borderColor: "rgb(69, 169, 230)",
+ fill: false,
+ data: []
+}, {
+ label: "So",
+ borderColor: "rgb(246, 250, 15)",
+ fill: false,
+ data: []
+}];
+
+fetch('/LastWeekDataAverage')
+ .then(function(response) {
+ return response.json();
+ })
+ .then(function(data) {
+ drawChart(data, datasets);
+ });
+
+function drawChart(gasData, datasets) {
+
+ var finishedData = {
+ labels: []
+ };
+
+ Object.keys(gasData).forEach(function(key) {
+ finishedData.labels.push(key);
+ datasets[0].data.push(gasData[key].Co);
+ datasets[1].data.push(gasData[key].No);
+ datasets[2].data.push(gasData[key].So);
+ });
+
+ finishedData.datasets = datasets;
+
+ var myLineChart = new Chart(ctx, {
+ type: 'line',
+ data: finishedData,
+ options: {
+ scales: {
+ xAxes: [{
+ time: {
+ unit: 'day'
+ }
+ }]
+ }
+ }
+ });
+}