mirror of
https://github.com/woodchen-ink/proxy-go.git
synced 2025-07-18 16:41:54 +08:00
fix(metrics): improve chart management in metrics dashboard
- Added logic to destroy existing charts before creating new ones, preventing memory leaks and ensuring proper chart updates. - Updated the currentCharts object to maintain references to the newly created charts, enhancing the management of chart instances. - These changes improve the performance and reliability of the metrics dashboard by ensuring that charts are correctly handled during updates.
This commit is contained in:
parent
660e60576d
commit
b5a3cfeee4
@ -700,7 +700,13 @@ var metricsTemplate = `
|
|||||||
};
|
};
|
||||||
chartInstance.update();
|
chartInstance.update();
|
||||||
} else {
|
} else {
|
||||||
chartInstance = new Chart(ctx, {
|
// 创建新图表前先销毁旧的
|
||||||
|
if (currentCharts[canvasId.replace('Chart', '')]) {
|
||||||
|
currentCharts[canvasId.replace('Chart', '')].destroy();
|
||||||
|
}
|
||||||
|
|
||||||
|
// 创建新图表
|
||||||
|
const newChart = new Chart(ctx, {
|
||||||
type: 'line',
|
type: 'line',
|
||||||
data: chartData,
|
data: chartData,
|
||||||
options: {
|
options: {
|
||||||
@ -722,6 +728,9 @@ var metricsTemplate = `
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// 更新 currentCharts 对象
|
||||||
|
currentCharts[canvasId.replace('Chart', '')] = newChart;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user