diff --git a/plugins/stats_dashboard/templates/robot_management.html b/plugins/stats_dashboard/templates/robot_management.html
index 4963e69..c4dcbf0 100644
--- a/plugins/stats_dashboard/templates/robot_management.html
+++ b/plugins/stats_dashboard/templates/robot_management.html
@@ -464,9 +464,6 @@
return;
}
- // 清空容器
- container.innerHTML = '';
-
// 准备数据
const labels = data.dates || [];
const messageData = (data.counts || []).map(count => parseInt(count) || 0);
@@ -476,16 +473,77 @@
return;
}
- // 创建表格显示数据
+ // 销毁之前的图表实例(如果存在)
+ if (this.charts.trendChart) {
+ this.charts.trendChart.destroy();
+ }
+
+ // 创建canvas元素
+ container.innerHTML = '';
+ const ctx = document.getElementById('messageChart').getContext('2d');
+
+ // 使用Chart.js创建图表
+ this.charts.trendChart = new Chart(ctx, {
+ type: 'bar',
+ data: {
+ labels: labels,
+ datasets: [{
+ label: '消息数量',
+ data: messageData,
+ backgroundColor: 'rgba(75, 192, 192, 0.5)',
+ borderColor: 'rgba(75, 192, 192, 1)',
+ borderWidth: 1
+ }]
+ },
+ options: {
+ responsive: true,
+ maintainAspectRatio: false,
+ scales: {
+ y: {
+ beginAtZero: true,
+ title: {
+ display: true,
+ text: '消息数量'
+ }
+ },
+ x: {
+ title: {
+ display: true,
+ text: '日期'
+ }
+ }
+ },
+ plugins: {
+ title: {
+ display: true,
+ text: '群组消息数量趋势',
+ font: {
+ size: 16
+ }
+ },
+ tooltip: {
+ callbacks: {
+ label: function(context) {
+ return `消息数量: ${context.raw}`;
+ }
+ }
+ }
+ }
+ }
+ });
+
+ // 添加表格显示详细数据
let tableHtml = `
-
-
-
- | 日期 |
- 消息数量 |
-
-
-
+
+
详细数据
+
+
+
+ | 日期 |
+ 消息数量 |
+
+
+
`;
for (let i = 0; i < labels.length; i++) {
@@ -498,39 +556,15 @@
}
tableHtml += `
-
-
- `;
-
- container.innerHTML = tableHtml;
-
- // 添加简单的可视化条形图
- const maxValue = Math.max(...messageData);
- let chartHtml = `
-
-
消息数量可视化
-
- `;
-
- for (let i = 0; i < labels.length; i++) {
- const percentage = (messageData[i] / maxValue) * 100;
- chartHtml += `
-
- `;
- }
-
- chartHtml += `
-
+
+
`;
- container.innerHTML += chartHtml;
+ // 在图表下方添加表格
+ const tableContainer = document.createElement('div');
+ tableContainer.innerHTML = tableHtml;
+ container.parentNode.insertBefore(tableContainer, container.nextSibling);
} catch (error) {
console.error('渲染趋势数据出错:', error);