-
Notifications
You must be signed in to change notification settings - Fork 0
/
drawCharts.js
108 lines (100 loc) · 2.85 KB
/
drawCharts.js
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
setInterval(function() {
main();
}, 3000);
async function main() {
const vitalSigns = await makeDbRequest();
populateTable(vitalSigns);
drawCharts(vitalSigns);
}
async function makeDbRequest() {
const url = 'read_db.php';
try {
const response = await fetch(url, {
method: 'POST',
});
if (!response.ok) {
throw new Error(`HTTP error! Status: ${response.status}`);
}
const responseData = await response.json();
// console.log('Success:', responseData);
return responseData;
} catch (error) {
console.error('Error:', error);
}
}
function populateTable(data) {
const rows = data.rows;
const tableBody = document.getElementById('vital-signs').querySelector('tbody');
tableBody.innerHTML = '';
rows.forEach(row => {
let tableRowMarkup =
`<tr id="tr-id-2" class="tr-class-2">
<td id="td-id-2" class="td-class-2">
${row.id}
</td>
<td>
${row.sensor_names}
</td>
<td>
${row.temperature_value}
</td>
<td>
${row.heart_rate_value}
</td>
</tr>`;
tableBody.innerHTML += tableRowMarkup;
});
}
function drawCharts(data) {
const value1 = JSON.parse(data.temperature);
const value2 = JSON.parse(data.heart_rate);
const reading_time = JSON.parse(data.reading_time);
let chartT = new Highcharts.Chart({
chart: { renderTo: 'chart-temperature' },
title: { text: 'Temperatura' },
series: [{
showInLegend: false,
data: value1
}],
plotOptions: {
line: {
animation: false,
dataLabels: { enabled: true }
},
series: { color: '#059e8a' }
},
xAxis: {
type: 'datetime',
categories: reading_time
},
yAxis: {
title: { text: 'Temperatura (Celsius)' }
//title: { text: 'Temperature (Fahrenheit)' }
},
credits: { enabled: false }
});
let chartHeart = new Highcharts.Chart({
chart: { renderTo: 'chart-heart-rate' },
title: { text: 'Ritmo Cardiaco' },
series: [{
showInLegend: false,
data: value2
}],
plotOptions: {
line: {
animation: false,
dataLabels: { enabled: true }
},
series: { color: '#059e8a' }
},
xAxis: {
type: 'datetime',
categories: reading_time
},
yAxis: {
title: { text: 'PPM(BPM)' }
//title: { text: 'Temperature (Fahrenheit)' }
},
credits: { enabled: false }
});
}