forked from narendra-NitRkl27/AgriSense
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathchatSetup.js
More file actions
51 lines (46 loc) · 1.54 KB
/
chatSetup.js
File metadata and controls
51 lines (46 loc) · 1.54 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
document.addEventListener('DOMContentLoaded', () => {
const initChart = () => {
const ctx = document.getElementById('weather-chart')?.getContext('2d');
if (!ctx) return;
const temps = [];
const times = [];
document.querySelectorAll('.forecast-item').forEach(item => {
const time = item.querySelector('.forecast-time')?.textContent;
const temp = item.querySelector('.forecast-temp')?.textContent;
if (time && temp) {
times.push(time);
temps.push(parseFloat(temp));
}
});
if (temps.length === 0) return;
new Chart(ctx, {
type: 'line',
data: {
labels: times,
datasets: [{
label: 'Temperature (°C)',
data: temps,
borderColor: 'rgb(75, 192, 192)',
tension: 0.4,
fill: false
}]
},
options: {
responsive: true,
plugins: {
legend: { display: false }
},
scales: {
x: { display: false },
y: { display: false }
}
}
});
};
// Initialize chart and retry if elements not ready
if (document.readyState === 'complete') {
initChart();
} else {
window.addEventListener('load', initChart);
}
});