fix: ucharts 组件引入错误,改用 JS API 方式
- @qiun/ucharts 不包含 Vue 组件 - 改用 uCharts JS 构造函数直接绘制 - 使用 uni.createCanvasContext 创建画布 - 添加 drawChart 方法在数据加载后绘制
This commit is contained in:
parent
cf699c9980
commit
4106fc78c7
@ -81,13 +81,12 @@
|
|||||||
|
|
||||||
<!-- 收益曲线 -->
|
<!-- 收益曲线 -->
|
||||||
<view v-else class="nav-chart-wrapper">
|
<view v-else class="nav-chart-wrapper">
|
||||||
<qiun-ucharts
|
<canvas
|
||||||
type="line"
|
canvas-id="navChartCanvas"
|
||||||
:opts="chartOpts"
|
id="navChartCanvas"
|
||||||
:chartData="chartData"
|
class="nav-canvas"
|
||||||
:canvas2d="true"
|
type="2d"
|
||||||
canvasId="navChartCanvas"
|
></canvas>
|
||||||
/>
|
|
||||||
</view>
|
</view>
|
||||||
|
|
||||||
<!-- 统计指标 -->
|
<!-- 统计指标 -->
|
||||||
@ -434,9 +433,11 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup>
|
<script setup>
|
||||||
import { ref, onMounted, getCurrentInstance, computed } from 'vue';
|
import { ref, onMounted, getCurrentInstance, computed, nextTick } from 'vue';
|
||||||
import { api } from '../../utils/api';
|
import { api } from '../../utils/api';
|
||||||
import qiunUcharts from '@qiun/ucharts/components/qiun-ucharts/qiun-ucharts.vue';
|
import uCharts from '@qiun/ucharts/u-charts.js';
|
||||||
|
|
||||||
|
let chartInstance = null;
|
||||||
|
|
||||||
// 获取 u-toast 实例
|
// 获取 u-toast 实例
|
||||||
const { proxy } = getCurrentInstance();
|
const { proxy } = getCurrentInstance();
|
||||||
@ -484,55 +485,59 @@ const navPeriod = ref('30d');
|
|||||||
const navHistory = ref([]);
|
const navHistory = ref([]);
|
||||||
const navStatistics = ref(null);
|
const navStatistics = ref(null);
|
||||||
|
|
||||||
// 图表数据
|
// 绘制图表
|
||||||
const chartData = computed(() => {
|
const drawChart = () => {
|
||||||
if (!navHistory.value || navHistory.value.length === 0) {
|
if (!navHistory.value || navHistory.value.length === 0) return;
|
||||||
return { categories: [], series: [] };
|
|
||||||
}
|
|
||||||
|
|
||||||
return {
|
nextTick(() => {
|
||||||
categories: navHistory.value.map(item => item.date.split('-').slice(1).join('/')),
|
const data = navHistory.value;
|
||||||
series: [{
|
|
||||||
name: '净值',
|
const chartData = {
|
||||||
data: navHistory.value.map(item => item.nav)
|
categories: data.map(item => item.date.split('-').slice(1).join('/')),
|
||||||
}]
|
series: [{
|
||||||
};
|
name: '净值',
|
||||||
});
|
data: data.map(item => item.nav)
|
||||||
|
}]
|
||||||
// 图表配置
|
};
|
||||||
const chartOpts = {
|
|
||||||
color: ['#064E3B'],
|
chartInstance = new uCharts({
|
||||||
padding: [15, 15, 0, 15],
|
type: 'line',
|
||||||
enableScroll: false,
|
canvas: uni.createCanvasContext('navChartCanvas'),
|
||||||
legend: {
|
width: uni.upx2px(640),
|
||||||
show: false
|
height: uni.upx2px(400),
|
||||||
},
|
pixelRatio: 1,
|
||||||
xAxis: {
|
categories: chartData.categories,
|
||||||
disableGrid: true,
|
series: chartData.series,
|
||||||
axisLine: false,
|
animation: true,
|
||||||
fontSize: 10,
|
color: ['#064E3B'],
|
||||||
fontColor: '#6B7280'
|
padding: [15, 15, 0, 15],
|
||||||
},
|
enableScroll: false,
|
||||||
yAxis: {
|
legend: {
|
||||||
data: [{ min: 0 }],
|
show: false
|
||||||
gridColor: '#E5E7EB',
|
},
|
||||||
gridType: 'dash',
|
xAxis: {
|
||||||
dashLength: 4,
|
disableGrid: true,
|
||||||
fontSize: 10,
|
axisLine: false,
|
||||||
fontColor: '#6B7280'
|
fontSize: 10,
|
||||||
},
|
fontColor: '#6B7280'
|
||||||
extra: {
|
},
|
||||||
line: {
|
yAxis: {
|
||||||
type: 'curve',
|
data: [{ min: 0 }],
|
||||||
width: 2,
|
gridColor: '#E5E7EB',
|
||||||
activeType: 'hollow'
|
gridType: 'dash',
|
||||||
},
|
dashLength: 4,
|
||||||
area: {
|
fontSize: 10,
|
||||||
type: 'curve',
|
fontColor: '#6B7280'
|
||||||
opacity: 0.3,
|
},
|
||||||
addLine: true
|
extra: {
|
||||||
}
|
line: {
|
||||||
}
|
type: 'curve',
|
||||||
|
width: 2,
|
||||||
|
activeType: 'hollow'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
// 交易表单
|
// 交易表单
|
||||||
@ -703,6 +708,11 @@ const fetchNavHistory = async () => {
|
|||||||
if (response.code === 200 && response.data) {
|
if (response.code === 200 && response.data) {
|
||||||
navHistory.value = response.data.navHistory || [];
|
navHistory.value = response.data.navHistory || [];
|
||||||
navStatistics.value = response.data.statistics || null;
|
navStatistics.value = response.data.statistics || null;
|
||||||
|
|
||||||
|
// 绘制图表
|
||||||
|
if (navHistory.value.length > 0) {
|
||||||
|
drawChart();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('获取净值历史失败:', error);
|
console.error('获取净值历史失败:', error);
|
||||||
@ -1299,6 +1309,11 @@ const deletePortfolio = async () => {
|
|||||||
height: 400rpx;
|
height: 400rpx;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.nav-canvas {
|
||||||
|
width: 640rpx;
|
||||||
|
height: 400rpx;
|
||||||
|
}
|
||||||
|
|
||||||
.period-tabs {
|
.period-tabs {
|
||||||
display: flex;
|
display: flex;
|
||||||
gap: 16rpx;
|
gap: 16rpx;
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user