146 lines
3.0 KiB
Vue
Raw Normal View History

<template>
<div class="j-line-chart" ref="JLineChart"></div>
</template>
<script>
import echarts from 'echarts4'
export default {
props: {
title: {
type: Object,
default: () => ({ text: '' })
},
grid: {
type: Array,
default: () => ['12%', '2%', '6%', '1%']
},
color: {
type: Array,
default: () => ['#FAC915', '#61D2B9', '#F67F51', '#7851F6']
},
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
},
tooltip: {
trigger: 'axis'
},
color,
xAxis: {
type: 'category',
boundaryGap: false,
data: xData,
axisTick: {
show: false
},
axisLabel: {
textStyle: {
color: 'rgba(255, 255, 255, .8)'
}
},
axisLine: {
lineStyle: {
type: [5, 10],
color: '#364252'
}
}
},
yAxis: {
type: 'value',
axisTick: {
show: false
},
axisLabel: {
textStyle: {
color: 'rgba(255, 255, 255, .8)'
}
},
axisLine: {
show: true,
lineStyle: {
type: [5, 10],
color: '#787E8A'
}
},
splitLine: {
lineStyle: {
type: [5, 10],
color: '#364252'
}
}
},
series: [
{
data: yData,
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
}
}
}
]
}
this.JLineChart.setOption(option)
}
}
}
</script>
<style>
.j-line-chart {
width: 100%;
height: 100%;
}
</style>