From a2c10eb54d462bf01434cad5a5d45d0f8c5fcfc2 Mon Sep 17 00:00:00 2001 From: Gzs2406 <2069733833@qq.com> Date: Fri, 3 Jan 2025 16:08:59 +0800 Subject: [PATCH] =?UTF-8?q?fix:=E6=9B=B4=E6=96=B0=E6=9B=B4=E6=96=B0?= =?UTF-8?q?=E6=97=B6=E9=97=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- router/api.py | 8 ++++---- templates/ordercount.html | 2 +- templates/streamordernamecount.html | 4 ++-- templates/streamordersummary.html | 15 ++++++++++++--- templates/streamsummary.html | 2 +- 5 files changed, 20 insertions(+), 11 deletions(-) diff --git a/router/api.py b/router/api.py index 5478412..fd82a10 100644 --- a/router/api.py +++ b/router/api.py @@ -12,7 +12,7 @@ def readKafka(): messages = [] try: # 读取消息,最多读取10条消息 - msg = consumer.poll(timeout_ms=500, max_records=50) + msg = consumer.poll(timeout_ms=1000, max_records=50) for partition, msgs in msg.items(): for message in msgs: messages.append(raw_Data_to_jsonstr(message.value.decode('utf-8'))) @@ -44,7 +44,7 @@ def orders_count_by_name(): messages = [] try: # 读取消息,最多读取10条消息 - msg = consumer.poll(timeout_ms=500, max_records=50) + msg = consumer.poll(timeout_ms=1000, max_records=50) for partition, msgs in msg.items(): for message in msgs: jsondata = json.loads(message.value.decode('utf-8')) @@ -66,7 +66,7 @@ def order_name_count(): messages = [] try: # 读取消息,最多读取10条消息 - msg = consumer.poll(timeout_ms=500, max_records=50) + msg = consumer.poll(timeout_ms=1000, max_records=50) for partition, msgs in msg.items(): for message in msgs: jsondata = json.loads(message.value.decode('utf-8')) @@ -88,7 +88,7 @@ def summary(): messages = [] try: # 读取消息,最多读取10条消息 - msg = consumer.poll(timeout_ms=500, max_records=50) + msg = consumer.poll(timeout_ms=1000, max_records=50) for partition, msgs in msg.items(): for message in msgs: jsondata = json.loads(message.value.decode('utf-8')) diff --git a/templates/ordercount.html b/templates/ordercount.html index 4accd45..4410aa4 100644 --- a/templates/ordercount.html +++ b/templates/ordercount.html @@ -80,7 +80,7 @@ } // 每5秒更新一次图表数据 - setInterval(fetchDataAndUpdateChart, 5000); + setInterval(fetchDataAndUpdateChart, 10000); // 初始数据加载 fetchDataAndUpdateChart(); diff --git a/templates/streamordernamecount.html b/templates/streamordernamecount.html index abfc0cf..e1a2e89 100644 --- a/templates/streamordernamecount.html +++ b/templates/streamordernamecount.html @@ -54,7 +54,7 @@ // 获取数据并更新图表 function fetchDataAndUpdateChart() { - fetch('/api/stream/ordernamecount') // 替换为你的实际API地址 + fetch('/api/stream/ordernamecount') .then(response => response.json()) .then(data => { // 统计每个订单名称的数量 @@ -82,7 +82,7 @@ } // 每5秒更新一次数据 - setInterval(fetchDataAndUpdateChart, 5000); + setInterval(fetchDataAndUpdateChart, 10000); // 初始数据加载 fetchDataAndUpdateChart(); diff --git a/templates/streamordersummary.html b/templates/streamordersummary.html index 1f0dff0..cdc24f1 100644 --- a/templates/streamordersummary.html +++ b/templates/streamordersummary.html @@ -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(); diff --git a/templates/streamsummary.html b/templates/streamsummary.html index e4343c2..e66268f 100644 --- a/templates/streamsummary.html +++ b/templates/streamsummary.html @@ -91,7 +91,7 @@ } // 每5秒更新一次数据 - setInterval(fetchDataAndUpdateChart, 5000); + setInterval(fetchDataAndUpdateChart, 10000); // 初始数据加载 fetchDataAndUpdateChart();