2022-08-03 15:14:14 +08:00
|
|
|
<template>
|
|
|
|
|
<div class="j-line-chart" ref="JLineChart"></div>
|
|
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
<script>
|
|
|
|
|
import echarts from 'echarts4'
|
|
|
|
|
export default {
|
|
|
|
|
props: {
|
|
|
|
|
title: {
|
|
|
|
|
type: Object,
|
2022-08-03 15:38:01 +08:00
|
|
|
default: () => ({ text: '' })
|
2022-08-03 15:14:14 +08:00
|
|
|
},
|
|
|
|
|
grid: {
|
|
|
|
|
type: Array,
|
2022-08-03 15:38:01 +08:00
|
|
|
default: () => ['12%', '2%', '6%', '1%']
|
2022-08-03 15:14:14 +08:00
|
|
|
},
|
|
|
|
|
color: {
|
|
|
|
|
type: Array,
|
2022-08-03 15:38:01 +08:00
|
|
|
default: () => ['#FAC915', '#61D2B9', '#F67F51', '#7851F6']
|
2022-08-03 15:14:14 +08:00
|
|
|
},
|
|
|
|
|
xData: {
|
|
|
|
|
required: true,
|
|
|
|
|
type: Array,
|
|
|
|
|
default: () => []
|
|
|
|
|
},
|
|
|
|
|
yData: {
|
|
|
|
|
required: true,
|
|
|
|
|
type: Array,
|
|
|
|
|
default: () => []
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
mounted() {
|
|
|
|
|
this.JLineChart = echarts.init(this.$refs.JLineChart)
|
|
|
|
|
this.createChart()
|
|
|
|
|
},
|
|
|
|
|
data() {
|
|
|
|
|
return { JLineChart: null }
|
|
|
|
|
},
|
|
|
|
|
methods: {
|
|
|
|
|
createChart() {
|
|
|
|
|
const { title, grid, color, xData, yData } = this
|
|
|
|
|
const option = {
|
|
|
|
|
title: {
|
|
|
|
|
text: title.text,
|
|
|
|
|
right: 20,
|
|
|
|
|
textStyle: {
|
|
|
|
|
fontSize: '14px',
|
|
|
|
|
color: '#5EC2D0',
|
|
|
|
|
fontWeight: 'normal'
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
grid: {
|
|
|
|
|
top: grid[0],
|
|
|
|
|
right: grid[1],
|
|
|
|
|
bottom: grid[2],
|
|
|
|
|
left: grid[3],
|
|
|
|
|
containLabel: true
|
|
|
|
|
},
|
2022-08-03 15:38:01 +08:00
|
|
|
tooltip: {
|
|
|
|
|
trigger: 'axis'
|
|
|
|
|
},
|
2022-08-03 15:14:14 +08:00
|
|
|
color,
|
|
|
|
|
xAxis: {
|
|
|
|
|
type: 'category',
|
2022-08-03 15:38:01 +08:00
|
|
|
boundaryGap: false,
|
2022-08-03 15:14:14 +08:00
|
|
|
data: xData,
|
2022-08-03 15:38:01 +08:00
|
|
|
axisTick: {
|
|
|
|
|
show: false
|
2022-08-03 15:14:14 +08:00
|
|
|
},
|
|
|
|
|
axisLabel: {
|
|
|
|
|
textStyle: {
|
2022-08-03 15:38:01 +08:00
|
|
|
color: 'rgba(255, 255, 255, .8)'
|
2022-08-03 15:14:14 +08:00
|
|
|
}
|
|
|
|
|
},
|
2022-08-03 15:38:01 +08:00
|
|
|
axisLine: {
|
|
|
|
|
lineStyle: {
|
|
|
|
|
type: [5, 10],
|
|
|
|
|
color: '#364252'
|
|
|
|
|
}
|
2022-08-03 15:14:14 +08:00
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
yAxis: {
|
|
|
|
|
type: 'value',
|
2022-08-03 15:38:01 +08:00
|
|
|
axisTick: {
|
|
|
|
|
show: false
|
|
|
|
|
},
|
|
|
|
|
axisLabel: {
|
|
|
|
|
textStyle: {
|
|
|
|
|
color: 'rgba(255, 255, 255, .8)'
|
2022-08-03 15:14:14 +08:00
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
axisLine: {
|
|
|
|
|
show: true,
|
|
|
|
|
lineStyle: {
|
2022-08-03 15:38:01 +08:00
|
|
|
type: [5, 10],
|
|
|
|
|
color: '#787E8A'
|
2022-08-03 15:14:14 +08:00
|
|
|
}
|
|
|
|
|
},
|
2022-08-03 15:38:01 +08:00
|
|
|
splitLine: {
|
|
|
|
|
lineStyle: {
|
|
|
|
|
type: [5, 10],
|
|
|
|
|
color: '#364252'
|
2022-08-03 15:14:14 +08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
series: [
|
|
|
|
|
{
|
|
|
|
|
data: yData,
|
2022-08-03 15:38:01 +08:00
|
|
|
type: 'line',
|
|
|
|
|
smooth: true,
|
|
|
|
|
areaStyle: {
|
|
|
|
|
color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
|
|
|
|
|
{
|
|
|
|
|
offset: 0,
|
|
|
|
|
color: 'rgba(250,201,21,0.6)'
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
offset: 1,
|
|
|
|
|
color: 'rgba(250,201,21,0.1)'
|
|
|
|
|
}
|
|
|
|
|
])
|
|
|
|
|
},
|
|
|
|
|
showSymbol: false,
|
|
|
|
|
itemStyle: {
|
|
|
|
|
emphasis: {
|
|
|
|
|
color: '#FAC915',
|
|
|
|
|
borderColor: '#FAC915',
|
|
|
|
|
borderWidth: 10
|
|
|
|
|
}
|
|
|
|
|
}
|
2022-08-03 15:14:14 +08:00
|
|
|
}
|
|
|
|
|
]
|
|
|
|
|
}
|
|
|
|
|
this.JLineChart.setOption(option)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
<style>
|
|
|
|
|
.j-line-chart {
|
|
|
|
|
width: 100%;
|
|
|
|
|
height: 100%;
|
|
|
|
|
}
|
|
|
|
|
</style>
|