fix:更新更新时间
This commit is contained in:
parent
64a34cc63d
commit
a2c10eb54d
@ -12,7 +12,7 @@ def readKafka():
|
|||||||
messages = []
|
messages = []
|
||||||
try:
|
try:
|
||||||
# 读取消息,最多读取10条消息
|
# 读取消息,最多读取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 partition, msgs in msg.items():
|
||||||
for message in msgs:
|
for message in msgs:
|
||||||
messages.append(raw_Data_to_jsonstr(message.value.decode('utf-8')))
|
messages.append(raw_Data_to_jsonstr(message.value.decode('utf-8')))
|
||||||
@ -44,7 +44,7 @@ def orders_count_by_name():
|
|||||||
messages = []
|
messages = []
|
||||||
try:
|
try:
|
||||||
# 读取消息,最多读取10条消息
|
# 读取消息,最多读取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 partition, msgs in msg.items():
|
||||||
for message in msgs:
|
for message in msgs:
|
||||||
jsondata = json.loads(message.value.decode('utf-8'))
|
jsondata = json.loads(message.value.decode('utf-8'))
|
||||||
@ -66,7 +66,7 @@ def order_name_count():
|
|||||||
messages = []
|
messages = []
|
||||||
try:
|
try:
|
||||||
# 读取消息,最多读取10条消息
|
# 读取消息,最多读取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 partition, msgs in msg.items():
|
||||||
for message in msgs:
|
for message in msgs:
|
||||||
jsondata = json.loads(message.value.decode('utf-8'))
|
jsondata = json.loads(message.value.decode('utf-8'))
|
||||||
@ -88,7 +88,7 @@ def summary():
|
|||||||
messages = []
|
messages = []
|
||||||
try:
|
try:
|
||||||
# 读取消息,最多读取10条消息
|
# 读取消息,最多读取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 partition, msgs in msg.items():
|
||||||
for message in msgs:
|
for message in msgs:
|
||||||
jsondata = json.loads(message.value.decode('utf-8'))
|
jsondata = json.loads(message.value.decode('utf-8'))
|
||||||
|
@ -80,7 +80,7 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 每5秒更新一次图表数据
|
// 每5秒更新一次图表数据
|
||||||
setInterval(fetchDataAndUpdateChart, 5000);
|
setInterval(fetchDataAndUpdateChart, 10000);
|
||||||
|
|
||||||
// 初始数据加载
|
// 初始数据加载
|
||||||
fetchDataAndUpdateChart();
|
fetchDataAndUpdateChart();
|
||||||
|
@ -54,7 +54,7 @@
|
|||||||
|
|
||||||
// 获取数据并更新图表
|
// 获取数据并更新图表
|
||||||
function fetchDataAndUpdateChart() {
|
function fetchDataAndUpdateChart() {
|
||||||
fetch('/api/stream/ordernamecount') // 替换为你的实际API地址
|
fetch('/api/stream/ordernamecount')
|
||||||
.then(response => response.json())
|
.then(response => response.json())
|
||||||
.then(data => {
|
.then(data => {
|
||||||
// 统计每个订单名称的数量
|
// 统计每个订单名称的数量
|
||||||
@ -82,7 +82,7 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 每5秒更新一次数据
|
// 每5秒更新一次数据
|
||||||
setInterval(fetchDataAndUpdateChart, 5000);
|
setInterval(fetchDataAndUpdateChart, 10000);
|
||||||
|
|
||||||
// 初始数据加载
|
// 初始数据加载
|
||||||
fetchDataAndUpdateChart();
|
fetchDataAndUpdateChart();
|
||||||
|
@ -35,6 +35,11 @@
|
|||||||
data: chartData,
|
data: chartData,
|
||||||
options: {
|
options: {
|
||||||
responsive: true,
|
responsive: true,
|
||||||
|
plugins: {
|
||||||
|
legend: {
|
||||||
|
display: true, // 显示图例
|
||||||
|
}
|
||||||
|
},
|
||||||
scales: {
|
scales: {
|
||||||
x: {
|
x: {
|
||||||
type: 'category', // X轴使用类别型
|
type: 'category', // X轴使用类别型
|
||||||
@ -54,9 +59,11 @@
|
|||||||
|
|
||||||
// 获取数据并更新图表
|
// 获取数据并更新图表
|
||||||
function fetchDataAndUpdateChart() {
|
function fetchDataAndUpdateChart() {
|
||||||
fetch('/api/stream/ordersummary') // 替换为你的实际API地址
|
fetch('/api/stream/ordersummary')
|
||||||
.then(response => response.json())
|
.then(response => response.json())
|
||||||
.then(data => {
|
.then(data => {
|
||||||
|
console.log('Received data:', data);
|
||||||
|
|
||||||
// 统计每个时间点的订单数量
|
// 统计每个时间点的订单数量
|
||||||
let orderCounts = {};
|
let orderCounts = {};
|
||||||
data.forEach(order => {
|
data.forEach(order => {
|
||||||
@ -71,6 +78,8 @@
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
console.log('Order counts:', orderCounts);
|
||||||
|
|
||||||
// 更新图表数据
|
// 更新图表数据
|
||||||
chartData.labels = Object.keys(orderCounts); // 设置X轴标签为时间
|
chartData.labels = Object.keys(orderCounts); // 设置X轴标签为时间
|
||||||
chartData.datasets[0].data = Object.values(orderCounts); // 设置Y轴数据为订单数量
|
chartData.datasets[0].data = Object.values(orderCounts); // 设置Y轴数据为订单数量
|
||||||
@ -81,8 +90,8 @@
|
|||||||
.catch(error => console.error('获取数据失败:', error));
|
.catch(error => console.error('获取数据失败:', error));
|
||||||
}
|
}
|
||||||
|
|
||||||
// 每5秒更新一次数据
|
// 每10秒更新一次数据
|
||||||
setInterval(fetchDataAndUpdateChart, 5000);
|
setInterval(fetchDataAndUpdateChart, 10000);
|
||||||
|
|
||||||
// 初始数据加载
|
// 初始数据加载
|
||||||
fetchDataAndUpdateChart();
|
fetchDataAndUpdateChart();
|
||||||
|
@ -91,7 +91,7 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 每5秒更新一次数据
|
// 每5秒更新一次数据
|
||||||
setInterval(fetchDataAndUpdateChart, 5000);
|
setInterval(fetchDataAndUpdateChart, 10000);
|
||||||
|
|
||||||
// 初始数据加载
|
// 初始数据加载
|
||||||
fetchDataAndUpdateChart();
|
fetchDataAndUpdateChart();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user