aboutsummaryrefslogtreecommitdiff
blob: 83f656a382a0158d41aeabf8c08da17762e48a07 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
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('/lastweek')
    .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'
                    }
                }]
            }
        }
    });
}