fix:更新更新时间

This commit is contained in:
2025-01-03 16:08:59 +08:00
parent 64a34cc63d
commit a2c10eb54d
5 changed files with 20 additions and 11 deletions

View File

@@ -35,6 +35,11 @@
data: chartData,
options: {
responsive: true,
plugins: {
legend: {
display: true, // 显示图例
}
},
scales: {
x: {
type: 'category', // X轴使用类别型
@@ -54,9 +59,11 @@
// 获取数据并更新图表
function fetchDataAndUpdateChart() {
fetch('/api/stream/ordersummary') // 替换为你的实际API地址
fetch('/api/stream/ordersummary')
.then(response => response.json())
.then(data => {
console.log('Received data:', data);
// 统计每个时间点的订单数量
let orderCounts = {};
data.forEach(order => {
@@ -71,6 +78,8 @@
}
});
console.log('Order counts:', orderCounts);
// 更新图表数据
chartData.labels = Object.keys(orderCounts); // 设置X轴标签为时间
chartData.datasets[0].data = Object.values(orderCounts); // 设置Y轴数据为订单数量
@@ -81,8 +90,8 @@
.catch(error => console.error('获取数据失败:', error));
}
// 每5秒更新一次数据
setInterval(fetchDataAndUpdateChart, 5000);
// 每10秒更新一次数据
setInterval(fetchDataAndUpdateChart, 10000);
// 初始数据加载
fetchDataAndUpdateChart();