From f8128ff327e66da05fa54fa16acbceb982f15478 Mon Sep 17 00:00:00 2001 From: aaron <> Date: Sun, 22 Feb 2026 09:37:54 +0800 Subject: [PATCH] 1 --- frontend/paper-trading.html | 37 ++++++++++++++++++++++++++++++++----- 1 file changed, 32 insertions(+), 5 deletions(-) diff --git a/frontend/paper-trading.html b/frontend/paper-trading.html index 23f5ac1..145df25 100644 --- a/frontend/paper-trading.html +++ b/frontend/paper-trading.html @@ -1532,7 +1532,8 @@ dailyReturns: [], loadingReturns: false, balanceChart: null, - returnsChart: null + returnsChart: null, + _renderingCharts: false // 防止重复渲染标志 }; }, mounted() { @@ -1923,8 +1924,22 @@ // 渲染图表 renderCharts() { - this.renderBalanceChart(); - this.renderReturnsChart(); + // 防止重复渲染 + if (this._renderingCharts) { + console.log('Charts already rendering, skipping...'); + return; + } + this._renderingCharts = true; + + try { + this.renderBalanceChart(); + this.renderReturnsChart(); + } finally { + // 延迟重置标志,确保渲染完成 + setTimeout(() => { + this._renderingCharts = false; + }, 200); + } }, // 渲染净值曲线图 @@ -1935,6 +1950,12 @@ return; } + // 检查 canvas 是否可见(offsetParent 不为 null 表示元素可见) + if (!canvas.offsetParent) { + console.warn('balanceChart canvas is not visible'); + return; + } + // 销毁已存在的图表 if (this.balanceChart) { this.balanceChart.destroy(); @@ -1943,7 +1964,7 @@ const ctx = canvas.getContext('2d'); if (!ctx) { - console.warn('Cannot get 2d context'); + console.warn('Cannot get 2d context for balanceChart'); return; } @@ -2038,6 +2059,12 @@ return; } + // 检查 canvas 是否可见 + if (!canvas.offsetParent) { + console.warn('returnsChart canvas is not visible'); + return; + } + // 销毁已存在的图表 if (this.returnsChart) { this.returnsChart.destroy(); @@ -2046,7 +2073,7 @@ const ctx = canvas.getContext('2d'); if (!ctx) { - console.warn('Cannot get 2d context'); + console.warn('Cannot get 2d context for returnsChart'); return; }