vue+elementUi+echarts 折线图组件
2020-07-22 本文已影响0人
小李疯狂输出
效果
🍕 此图并非折线图饼图联动 折线图饼图联动组件飞机票
🥟饼图点击事件再饼图组件中 饼图组件飞机票
🍗主要看折线图部分,动态变化折现条数
录制1.gif
折线图组件 mutiLine.vue
<template>
<div :class="className" :id="id" :style="{height:height,width:width}"></div>
</template>
<script>
import echarts from 'echarts'
import { debounce } from '@/utils'
require('echarts/theme/macarons') // echarts theme
export default {
props: {
lineData: {
type: Object,
default: {}
},
className: {
type: String,
default: 'chart'
},
id: {
type: String,
default: 'chart'
},
width: {
type: String,
default: '100%'
},
height: {
type: String,
default: '420px'
},
autoResize: {
type: Boolean,
default: true
},
},
data() {
return {
chart: null
}
},
mounted() {
this.$nextTick(function () {
setTimeout(this.initChart(), 200);
})
},
methods: {
initChart() {
this.chart = echarts.init(document.getElementById(this.id), 'macarons')
this.chart.clear();//清除画布内容
this.chart.setOption({
backgroundColor: '#ffffff',
title: {
text: '', //标题
},
tooltip: {
trigger: 'axis'
},
legend: {
top: 0,
icon: 'rect',
itemWidth: 14,
itemHeight: 5,
itemGap: 13,
data: this.lineData.yData, //导航数据
right: '50%',
textStyle: {
fontSize: 12,
color: '#000000'
}
},
grid: {
top: 100,
left: '3%',
right: '4%',
bottom: '2%',
containLabel: true
},
xAxis: [{
type: 'category',
boundaryGap: false,
axisLine: {
lineStyle: {
color: '#008acd'
}
},
data: this.lineData.yData,
}],
yAxis: [{
type: 'value',
name: '',
axisTick: {
show: false
},
axisLine: {
lineStyle: {
color: '#008acd'
}
},
axisLabel: {
margin: 10,
textStyle: {
fontSize: 14
}
},
splitLine: {
lineStyle: {
color: '#eeeeee'
}
}
}],
series: this.lineData.series
})
}
},
//折现数据通过变量传递
watch: {
lineData: {
deep: true,
handler(val) {
console.log('折线图监听', val)
if (val) {
setTimeout(this.initChart(), 100);
}
}
},
}
}
</script>
父组件引用
<muti-line :lineData="lineData"></muti-line>
import mutiLine from "@/components/Charts/mutiLine";
export default{
components:{ mutiLine }
}
data(){
return{ lineData:{} }
}