modified: server.js

modified:   static/js/sensor-1.js
This commit is contained in:
IrisVega 2024-07-20 17:38:37 +08:00
parent 3ae436f20f
commit d305f0e03c
2 changed files with 11 additions and 7 deletions

View File

@ -60,14 +60,18 @@ function getLatestSensorData(callback) {
callback({ error: 'Error fetching latest sensor data' }); callback({ error: 'Error fetching latest sensor data' });
return; return;
} }
const data = results[0]; const data = results[0];
const timestamps = data.map(row => new Date(row.timestamp).toISOString().slice(0, 19).replace('T', ' '));
const temperatures = data.map(row => row.temperature);
const humidities = data.map(row => row.humidity);
const co2 = data.map(row => row.co2);
const pressure = data.map(row => row.pressure);
callback({ callback({
temperature: data.temperature, timestamps,
humidity: data.humidity, temperatures,
co2: data.co2, humidities,
pressure: data.pressure, co2,
timestamps: data.timestamp.map(row => new Date(row.timestamp).toISOString().slice(0, 19).replace('T', ' ')) pressure
}); });
}); });
} }

View File

@ -27,7 +27,7 @@ document.addEventListener('DOMContentLoaded', function () {
// 添加新的数据 // 添加新的数据
timestamps.push(data.timestamps); timestamps.push(data.timestamps);
temperatures.push(data.temperature); temperatures.push(data.temperatures);
updateChart(); updateChart();
}); });