2025-09-04 13:42:48 +08:00
|
|
|
<template>
|
|
|
|
|
<div class="echarts">
|
2025-09-09 09:39:15 +08:00
|
|
|
<div class="chart-container" >
|
|
|
|
|
<div class="content-header" v-if="chartOptions.title">
|
2025-09-04 13:42:48 +08:00
|
|
|
<div class="verline"></div>
|
|
|
|
|
<span>{{ chartOptions.title }}</span>
|
|
|
|
|
</div>
|
2025-09-09 09:39:15 +08:00
|
|
|
<!-- {{ chartData.ydata }} -->
|
|
|
|
|
|
2025-09-04 13:42:48 +08:00
|
|
|
<div ref="chartContainer" class="echarts-content"></div>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
</template>
|
|
|
|
|
<script>
|
|
|
|
|
export default {
|
|
|
|
|
name: 'PredictEcharts',
|
|
|
|
|
props: {
|
|
|
|
|
chartOptions: {
|
|
|
|
|
type: Object,
|
|
|
|
|
default: () => {}, // 默认空对象
|
|
|
|
|
required: false // 非必须
|
|
|
|
|
},
|
|
|
|
|
chartData: {
|
2025-09-09 09:39:15 +08:00
|
|
|
type: Object,
|
|
|
|
|
default: () => ({}), // 默认空对象
|
2025-09-04 13:42:48 +08:00
|
|
|
required: false // 非必须
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
data() {
|
|
|
|
|
return {
|
|
|
|
|
chartInstances: [] // 存储 ECharts 实例
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
mounted() {
|
|
|
|
|
|
2025-09-09 09:39:15 +08:00
|
|
|
// this.$nextTick(() => {
|
|
|
|
|
// // 确保 DOM 完全渲染
|
|
|
|
|
// this.initCharts()
|
|
|
|
|
// window.addEventListener('resize', this.handleResize)
|
|
|
|
|
// })
|
2025-09-04 13:42:48 +08:00
|
|
|
},
|
|
|
|
|
beforeUnmount() {
|
|
|
|
|
window.removeEventListener('resize', this.handleResize)
|
|
|
|
|
this.chartInstances.forEach((chart) => chart && chart.dispose())
|
|
|
|
|
},
|
|
|
|
|
methods: {
|
|
|
|
|
initCharts() {
|
2025-09-09 09:39:15 +08:00
|
|
|
const {infoKeys,dataKey,type,smooth}=this.chartOptions
|
2025-09-04 13:42:48 +08:00
|
|
|
|
|
|
|
|
const dom = this.$refs.chartContainer
|
|
|
|
|
if (!dom) return
|
|
|
|
|
|
|
|
|
|
const chart = this.$echarts.init(dom)
|
|
|
|
|
this.chartInstances.push(chart) // 存储实例
|
|
|
|
|
|
|
|
|
|
// 设置图表配置
|
|
|
|
|
chart.setOption({
|
|
|
|
|
tooltip: {
|
|
|
|
|
trigger: 'axis',
|
|
|
|
|
axisPointer: {
|
|
|
|
|
type: 'shadow'
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
legend: {
|
|
|
|
|
top: 20,
|
|
|
|
|
textStyle: {
|
|
|
|
|
color: '#fff'
|
|
|
|
|
},
|
|
|
|
|
data: infoKeys.map((info) => info.label)
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
grid: {
|
|
|
|
|
left: '3%',
|
|
|
|
|
right: '3%',
|
2025-09-09 09:39:15 +08:00
|
|
|
bottom: '15%',
|
2025-09-17 14:54:33 +08:00
|
|
|
// containLabel: true
|
2025-09-04 13:42:48 +08:00
|
|
|
},
|
2025-09-09 09:39:15 +08:00
|
|
|
dataZoom: [
|
|
|
|
|
{
|
|
|
|
|
type: 'slider', // 滑动条型
|
|
|
|
|
show: true,
|
|
|
|
|
xAxisIndex: 0, // 控制第一个X轴
|
|
|
|
|
start: 0, // 初始显示范围起点(百分比)
|
2025-09-11 16:14:55 +08:00
|
|
|
end: 100, // 初始显示范围终点(百分比)
|
2025-09-09 09:39:15 +08:00
|
|
|
height: 20, // 滑动条高度
|
|
|
|
|
bottom: 10 // 距离底部距离
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
type: 'inside', // 内置型(鼠标滚轮/拖拽交互)
|
|
|
|
|
xAxisIndex: 0,
|
|
|
|
|
start: 0,
|
2025-09-11 16:14:55 +08:00
|
|
|
end: 100
|
2025-09-09 09:39:15 +08:00
|
|
|
}
|
|
|
|
|
],
|
2025-09-04 13:42:48 +08:00
|
|
|
xAxis: {
|
|
|
|
|
type: 'category',
|
2025-09-09 09:39:15 +08:00
|
|
|
data: this.chartData.xdata,
|
2025-09-04 13:42:48 +08:00
|
|
|
axisLine: {
|
|
|
|
|
show: true,
|
|
|
|
|
lineStyle: {
|
|
|
|
|
color: '#fff' // x轴线颜色
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
axisLabel: {
|
|
|
|
|
color: '#fff'
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
axisTick: {
|
|
|
|
|
lineStyle: {
|
|
|
|
|
color: '#fff' // x 轴刻度线颜色
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
},
|
|
|
|
|
yAxis: {
|
|
|
|
|
type: 'value',
|
|
|
|
|
axisLine: {
|
|
|
|
|
show: true,
|
|
|
|
|
lineStyle: {
|
|
|
|
|
color: '#fff' // y轴线颜色
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
axisLabel: {
|
|
|
|
|
color: '#fff'
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
splitLine: {
|
|
|
|
|
lineStyle: {
|
|
|
|
|
color: '#A6B8DD', // 网格线颜色,
|
|
|
|
|
type: 'dashed'
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
series: infoKeys.map((info, i) => {
|
|
|
|
|
return {
|
|
|
|
|
name: info.label,
|
|
|
|
|
smooth: smooth || false,
|
|
|
|
|
type: type,
|
2025-09-09 09:39:15 +08:00
|
|
|
data: this.chartData.ydata[info.key],
|
2025-09-04 13:42:48 +08:00
|
|
|
...info.seriesOptions,
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
// })
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
handleResize() {
|
|
|
|
|
this.chartInstances.forEach((chart) => chart && chart.resize())
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
<style lang="scss" scoped>
|
|
|
|
|
.content {
|
|
|
|
|
height: 100%;
|
|
|
|
|
width: 100%;
|
|
|
|
|
}
|
|
|
|
|
.echarts {
|
|
|
|
|
display: flex;
|
|
|
|
|
height: 100%;
|
|
|
|
|
width: 100%;
|
|
|
|
|
color: #fff;
|
|
|
|
|
.chart-container {
|
|
|
|
|
width: 100%;
|
|
|
|
|
height: 100%;
|
|
|
|
|
}
|
|
|
|
|
& > div {
|
|
|
|
|
|
|
|
|
|
width: 100%;
|
|
|
|
|
height: 100%;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
.content-header {
|
|
|
|
|
height: 20px;
|
|
|
|
|
font-size: 12px;
|
|
|
|
|
display: flex;
|
|
|
|
|
align-items: center;
|
|
|
|
|
margin-left: 3%;
|
|
|
|
|
.verline {
|
|
|
|
|
margin-right: 10px;
|
|
|
|
|
background: linear-gradient(
|
|
|
|
|
180deg,
|
|
|
|
|
rgba(0, 230, 172, 1) 0%,
|
|
|
|
|
rgba(0, 210, 255, 1) 98.78%,
|
|
|
|
|
rgba(0, 210, 255, 1) 100%
|
|
|
|
|
),
|
|
|
|
|
rgba(1, 223, 239, 1);
|
|
|
|
|
width: 4px;
|
|
|
|
|
height: 20px;
|
|
|
|
|
border-radius: 6px;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
.echarts-content{
|
|
|
|
|
height: calc(100% - 20px);
|
|
|
|
|
width: 100%;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
</style>
|