更新 src/uni_modules/cxc-szcx-multiLineChart/components/cxc-szcx-multiLineChart/cxc-szcx-multiLineChart.vue

This commit is contained in:
ldeyun 2025-09-15 15:05:38 +00:00
parent 6bac6dc89d
commit 92d48433b8

View File

@ -1,21 +1,7 @@
<route lang="json5" type="page">
{
layout: 'default',
style: {
navigationStyle: 'custom',
navigationBarTitleText: '历史数据图表',
},
}
</route>
<template>
<PageLayout :navbarShow="false">
<view>
<!-- ECharts图表 -->
<view class="chart-container">
<l-echart ref="chart" @finished="initChart" />
</view>
</view>
</PageLayout>
<view >
<l-echart ref="chart" @finished="drawChart" />
</view>
</template>
<script setup>
@ -75,7 +61,7 @@
// 1. chartOption.value
const generateOptions = () => {
console.log(23)
const serie = []; //
const yData = []; // Y
const xData = []; // X
@ -114,7 +100,7 @@
const legendName = `${yFieldItem.name}(${yFieldItem.unit})`;
legendData.push(legendName);
console.log(1, legendData)
// Yssll
if (yFieldItem.field === 'ssll') {
@ -122,7 +108,7 @@
yaxisTemp.nameGap = -15;
} else {
yaxisTemp.position = 'right';
yaxisTemp.offset = 40 * positionIndex;
yaxisTemp.offset = 30 * positionIndex;
positionIndex++;
}
@ -131,6 +117,7 @@
yaxisTemp.min = yFieldItem.min ?? 0; // min0
yaxisTemp.max = yFieldItem.max ?? 100; // max100
yaxisTemp.axisLine.lineStyle.color = colorData.value[i]?.color || '#61A0A8'; //
// yaxisTemp.show=false
yData.push(yaxisTemp);
@ -149,6 +136,7 @@
// this.serie.pushseriepush
serie.push(serieTemp);
}
//
@ -162,12 +150,13 @@
trigger: 'axis',
alwaysShowContent: true,
axisPointer: {
type: 'cross'
type: 'line',
show:false
}
},
toolbox: {
showTitle: true,
orient: 'vertical',
orient: 'horizontal',
feature: {
dataView: {
show: true,
@ -180,19 +169,21 @@
show: true
}
},
left: '0%',
top: '10%'
right: '10%',
top: '0'
},
legend: {
data: legendData,
itemGap: 5,
padding: [35, 5, 25, 5],
type: 'scroll'
type: 'scroll',
show:true
},
grid: {
top: '15%',
left: '5%',
right: `${10 + positionIndex * 10}%`, // Y
width:'auto',
top: '20%',
left: '5px',
right: '5px', // Y
bottom: 20,
containLabel: true
},
@ -201,6 +192,7 @@
axisTick: {
alignWithLabel: true
},
show:true,
data: xData
},
yAxis: yData,
@ -211,6 +203,7 @@
// 2. 访
const processSeriesData = () => {
const ssData = props.dataList;
// 访chartOption.value
const xData = [...chartOption.value.xAxis.data]; // X series
const serie = [...chartOption.value.series]; //
@ -238,7 +231,9 @@
// Ythis.seriethis.maxArrValue
serie.forEach((serieItem, mm) => {
const maxValue = maxArrValue(serieItem.data);
yData[mm].max = Math.round(maxValue * 1.2) || 100; // 0100
console.log(1,maxValue)
yData[mm].max = Math.round(maxValue * 12)/10 || 100; // 0100
console.log(2,yData[mm].max)
});
// .value
@ -251,7 +246,7 @@
series: serie,
yAxis: yData
};
console.log(22, chartOption.value)
};
// 3. NaN
@ -272,10 +267,8 @@
() => props.dataList,
(newVal) => {
if (newVal.length === 0) return; //
console.log(33, props.dataList)
console.log(44, props.yFields)
initChart()
updateChart();
drawChart()
}, {
deep: true,
immediate: true
@ -283,36 +276,24 @@
);
// 5. chartOption.value
const initChart = async () => {
const drawChart = async () => {
//
chartOption.value = generateOptions();
processSeriesData()
if (!chart.value) return;
// EChartssetTimeoutasync/await
const myChart = await chart.value.init(echarts);
myChart.setOption(chartOption.value);
// resize
window.addEventListener('resize', () => {
myChart.resize();
});
};
// 6. 访chartOption.value
const updateChart = () => {
if (!myChart.value || !chartOption.value) {
console.warn('ECharts实例未初始化');
return;
}
processSeriesData();
myChart.value.setOption(chartOption.value, true);
};
//
onMounted(() => {
setTimeout(() => {
initChart();
drawChart();
}, 500)
});
@ -329,45 +310,5 @@
</script>
<style scoped>
.chart-container {
width: 100%;
height: 30vh;
min-height: 200px;
padding: 20rpx;
background: linear-gradient(145deg, #f8f9fa 0%, #ffffff 100%);
border-radius: 16rpx;
box-shadow: 0 8rpx 32rpx rgba(0, 0, 0, 0.08);
position: relative;
overflow: hidden;
}
/* 加载占位符(数据为空时显示) */
.chart-container::before {
content: '数据加载中...';
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
color: #666;
font-size: 28rpx;
z-index: 1;
/* 数据加载完成后隐藏 */
opacity: v-bind('chartOption.value.series?.length > 0 ? 0 : 1');
}
.chart-wrapper {
width: 100%;
height: 100%;
transition: opacity 0.3s ease;
}
/* 移动端优化调整右侧间距避免Y轴标签被截断 */
@media screen and (max-width: 768px) {
.chart-container {
height: 30vh;
min-height: 200px;
padding: 10rpx;
border-radius: 12rpx;
}
}
</style>