update
This commit is contained in:
parent
4a357b56c0
commit
55202f959b
@ -1907,9 +1907,11 @@
|
||||
const data = await response.json();
|
||||
if (data.success) {
|
||||
this.dailyReturns = data.data;
|
||||
// 等待 DOM 更新后渲染图表
|
||||
// 等待 DOM 更新后渲染图表,添加额外延迟确保 canvas 完全渲染
|
||||
this.$nextTick(() => {
|
||||
setTimeout(() => {
|
||||
this.renderCharts();
|
||||
}, 100);
|
||||
});
|
||||
}
|
||||
} catch (e) {
|
||||
@ -1928,17 +1930,35 @@
|
||||
// 渲染净值曲线图
|
||||
renderBalanceChart() {
|
||||
const canvas = document.getElementById('balanceChart');
|
||||
if (!canvas) return;
|
||||
if (!canvas) {
|
||||
console.warn('balanceChart canvas not found');
|
||||
return;
|
||||
}
|
||||
|
||||
// 销毁已存在的图表
|
||||
if (this.balanceChart) {
|
||||
this.balanceChart.destroy();
|
||||
this.balanceChart = null;
|
||||
}
|
||||
|
||||
const ctx = canvas.getContext('2d');
|
||||
if (!ctx) {
|
||||
console.warn('Cannot get 2d context');
|
||||
return;
|
||||
}
|
||||
|
||||
// 确保有数据
|
||||
if (!this.dailyReturns || this.dailyReturns.length === 0) {
|
||||
console.warn('No daily returns data');
|
||||
return;
|
||||
}
|
||||
|
||||
const labels = this.dailyReturns.map(d => d.date);
|
||||
const balanceData = this.dailyReturns.map(d => d.balance);
|
||||
|
||||
console.log('Rendering balance chart:', { labels, balanceData });
|
||||
|
||||
try {
|
||||
this.balanceChart = new Chart(ctx, {
|
||||
type: 'line',
|
||||
data: {
|
||||
@ -2004,23 +2024,45 @@
|
||||
}
|
||||
}
|
||||
});
|
||||
console.log('Balance chart rendered successfully');
|
||||
} catch (e) {
|
||||
console.error('Error rendering balance chart:', e);
|
||||
}
|
||||
},
|
||||
|
||||
// 渲染收益率柱状图
|
||||
renderReturnsChart() {
|
||||
const canvas = document.getElementById('returnsChart');
|
||||
if (!canvas) return;
|
||||
if (!canvas) {
|
||||
console.warn('returnsChart canvas not found');
|
||||
return;
|
||||
}
|
||||
|
||||
// 销毁已存在的图表
|
||||
if (this.returnsChart) {
|
||||
this.returnsChart.destroy();
|
||||
this.returnsChart = null;
|
||||
}
|
||||
|
||||
const ctx = canvas.getContext('2d');
|
||||
if (!ctx) {
|
||||
console.warn('Cannot get 2d context');
|
||||
return;
|
||||
}
|
||||
|
||||
// 确保有数据
|
||||
if (!this.dailyReturns || this.dailyReturns.length === 0) {
|
||||
console.warn('No daily returns data');
|
||||
return;
|
||||
}
|
||||
|
||||
const labels = this.dailyReturns.map(d => d.date);
|
||||
const returnsData = this.dailyReturns.map(d => d.return_percent);
|
||||
const colors = returnsData.map(v => v >= 0 ? '#00ff41' : '#ff4444');
|
||||
|
||||
console.log('Rendering returns chart:', { labels, returnsData });
|
||||
|
||||
try {
|
||||
this.returnsChart = new Chart(ctx, {
|
||||
type: 'bar',
|
||||
data: {
|
||||
@ -2076,6 +2118,10 @@
|
||||
}
|
||||
}
|
||||
});
|
||||
console.log('Returns chart rendered successfully');
|
||||
} catch (e) {
|
||||
console.error('Error rendering returns chart:', e);
|
||||
}
|
||||
}
|
||||
},
|
||||
computed: {
|
||||
@ -2161,9 +2207,11 @@
|
||||
if (this.dailyReturns.length === 0) {
|
||||
this.fetchDailyReturns();
|
||||
} else {
|
||||
// 数据已存在,需要重新渲染图表
|
||||
// 数据已存在,需要重新渲染图表,添加延迟确保 DOM 显示
|
||||
this.$nextTick(() => {
|
||||
setTimeout(() => {
|
||||
this.renderCharts();
|
||||
}, 100);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user