-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathThingspeak.html
More file actions
111 lines (107 loc) · 3.01 KB
/
Copy pathThingspeak.html
File metadata and controls
111 lines (107 loc) · 3.01 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
110
111
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Health Monitoring System</title>
<!-- Include Chart.js -->
<script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
<style>
/* Add your CSS styles here */
body {
font-family: Arial, sans-serif;
}
.container {
width: 80%;
margin: auto;
text-align: center;
}
canvas {
margin-top: 20px;
}
</style>
</head>
<body>
<div class="container">
<h1>Health Monitoring System</h1>
<canvas id="myChart"></canvas>
</div>
<script>
// Fetch data from ThingSpeak API
const apiKey = "DLNSD9H7UCPMOFBR";
const url = "https://api.thingspeak.com/channels/2526365/status.json?api_key=" + apiKey;
fetch(url)
.then(response => response.json())
.then(data => {
// Extract data points
const field1Data = data.channel.field1;
const field2Data = data.channel.field2;
// Prepare labels and data for the chart
const labels = [];
const pulseValues = [];
const temperatureValues = [];
field1Data.forEach(entry => {
labels.push(entry.created_at);
pulseValues.push(entry.field1);
temperatureValues.push(entry.field2);
});
// Create the chart
const ctx = document.getElementById('myChart').getContext('2d');
const myChart = new Chart(ctx, {
type: 'line',
data: {
labels: labels,
datasets: [{
label: 'Pulse Values',
data: pulseValues,
borderColor: 'rgb(75, 192, 192)',
tension: 0.1,
yAxisID: 'pulse-axis'
},
{
label: 'Temperature Values',
data: temperatureValues,
borderColor: 'rgb(255, 99, 132)',
tension: 0.1,
yAxisID: 'temperature-axis'
}]
},
options: {
scales: {
x: {
type: 'time',
time: {
displayFormats: {
hour: 'h:mm:ss a'
}
}
},
pulse-axis: {
type: 'linear',
position: 'left',
title: {
display: true,
text: 'Pulse'
}
},
temperature-axis: {
type: 'linear',
position: 'right',
title: {
display: true,
text: 'Temperature'
},
grid: {
drawOnChartArea: false
}
}
}
}
});
})
.catch(error => {
console.error('Error fetching data:', error);
});
</script>
</body>
</html>