修复网络流量图表显示异常问题

This commit is contained in:
Alex Yang
2025-12-06 11:42:01 +08:00
parent 5d4da5ddb4
commit be1edbc7ef
2 changed files with 36572 additions and 35 deletions

File diff suppressed because it is too large Load Diff

View File

@@ -2239,6 +2239,34 @@ function _updateCharts({ cpuData, memoryData, diskData, networkData }) {
return summedData; return summedData;
}; };
// 计算流量差值的辅助函数
const calculateTrafficDiff = (data) => {
if (!Array.isArray(data) || data.length <= 1) {
return data;
}
// 确保数据按时间排序
const sortedData = [...data].sort((a, b) => new Date(a.time) - new Date(b.time));
// 计算每个时间点与前一个时间点的差值
const diffData = [];
for (let i = 1; i < sortedData.length; i++) {
const current = sortedData[i];
const previous = sortedData[i - 1];
// 计算差值,确保为正数
const diff = {
time: current.time,
value: Math.max(0, current.value - previous.value)
};
diffData.push(diff);
}
return diffData;
};
// 更新网络流量趋势图表(发送总和和接收总和) // 更新网络流量趋势图表(发送总和和接收总和)
if (networkData && charts.network) { if (networkData && charts.network) {
let txBytesData, rxBytesData; let txBytesData, rxBytesData;
@@ -2268,10 +2296,13 @@ function _updateCharts({ cpuData, memoryData, diskData, networkData }) {
// 排序发送数据 // 排序发送数据
const sortedTxBytes = sortDataByTime(txBytesData); const sortedTxBytes = sortDataByTime(txBytesData);
// 计算流量差值,只显示指定时间范围内的流量变化
const diffTxBytes = calculateTrafficDiff(sortedTxBytes);
// 转换为MB // 转换为MB
const txBytesSumData = sortedTxBytes.map(item => ({ const txBytesSumData = diffTxBytes.map(item => ({
time: item.time, time: item.time,
value: item.value / (1024 * 1024) // 直接转换为MB value: item.value / (1024 * 1024) // 转换为MB
})); }));
// 使用固定份数X轴数据计算 // 使用固定份数X轴数据计算
@@ -2287,10 +2318,13 @@ function _updateCharts({ cpuData, memoryData, diskData, networkData }) {
// 排序接收数据 // 排序接收数据
const sortedRxBytes = sortDataByTime(rxBytesData); const sortedRxBytes = sortDataByTime(rxBytesData);
// 计算流量差值,只显示指定时间范围内的流量变化
const diffRxBytes = calculateTrafficDiff(sortedRxBytes);
// 转换为MB // 转换为MB
const rxBytesSumData = sortedRxBytes.map(item => ({ const rxBytesSumData = diffRxBytes.map(item => ({
time: item.time, time: item.time,
value: item.value / (1024 * 1024) // 直接转换为MB value: item.value / (1024 * 1024) // 转换为MB
})); }));
// 使用固定份数X轴数据计算 // 使用固定份数X轴数据计算