-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
109 lines (97 loc) · 3.32 KB
/
Copy pathindex.html
File metadata and controls
109 lines (97 loc) · 3.32 KB
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
<!doctype html>
<html>
<head>
<title>Graphics</title>
<script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
</head>
<body >
<h1>Graphics</h1>
<div style="display: flex; ">
<div style="width: 50%;">
<canvas id="sensorDigital"></canvas>
</div>
</div>
</div>
<script>
/*var sensorAnalogico = new Chart(document.getElementById('sensorAnalogico').getContext('2d'), {
type: 'line',
data: {
datasets: [{
label: 'Analogico',
borderColor: '#63B1BC',
backgroundColor: '#ED145B'
}]
},
options: {
scales: {
x: {
beginAtZero: true
},
y: {
title: {
display: true,
text: '(%)'
},
beginAtZero: true,
},
},
}
});*/
var sensorDigital = new Chart(document.getElementById('sensorDigital').getContext('2d'), {
type: 'line',
data: {
datasets: [{
label: 'Digital',
borderColor: '#63B1BC',
backgroundColor: '#0762C8'
}]
},
options: {
scales: {
x: {
beginAtZero: true
},
y: {
title: {
display: true,
text: '(0-1)'
},
beginAtZero: true
}
}
}
});
var paginacao = {};
var tempo = {};
function obterDados(grafico, endpoint) {
fetch('http://localhost:3300/sensores/' + endpoint)
.then(response => response.json())
.then(valores => {
if (paginacao[endpoint] == null) {
paginacao[endpoint] = 0;
}
if (tempo[endpoint] == null) {
tempo[endpoint] = 0;
}
var ultimaPaginacao = paginacao[endpoint];
paginacao[endpoint] = valores.length;
valores = valores.slice(ultimaPaginacao);
valores.forEach((valor) => {
if (grafico.data.labels.length == 10 && grafico.data.datasets[0].data.length == 10) {
grafico.data.labels.shift();
grafico.data.datasets[0].data.shift();
}
grafico.data.labels.push(tempo[endpoint]++);
grafico.data.datasets[0].data.push(parseFloat(valor));
grafico.update();
});
})
.catch(error => console.error('Erro ao obter dados:', error));
}
setInterval(() => {
//obterDados(sensorAnalogico, 'analogico');
obterDados(sensorDigital, 'digital');
}, 1000);
</script>
</body>
</html>