mounted () {
this.drawLine()
},
methods: {
drawLine () {
// 基于准备好的dom,初始化echarts实例
let myChart = this.$echarts.init(document.getElementById('myChart'))
// 绘制图表
myChart.setOption({
title: {
text: 'XXXXXX',
left: 'center'
},
tooltip: {
trigger: 'item',
formatter: '收入类型分布<br/>{b} : {c} ({d}%)'
},
legend: {
bottom: 10,
left: 'center',
data: ['1', '2', '3,'4', '其他']
},
series: [{
type: 'pie',
radius: '65%',
center: ['50%', '50%'],
selectedMode: 'single',
data: [
{value: 100, name: '1'},
{value: 120, name: '2'},
{value: 300, name: '3'},
{value: 260, name: '4'},
{value: 80, name: '其他'}
]
}]
})
window.addEventListener('resize', function () { //自适应屏幕大小
myChart.resize()
})
},
}
<el-tabs v-model="activeName" type="card" @tab-click="handleClick">
handleClick (tab, event) { //点击tab切换时 重新调用显示图( this.$nextTick) 防止echart图宽度问题
console.log(tab.index)
if (tab.index == 0) {
this.$nextTick(() => {
this.drawLine()
this.draw2()
})
} else if (tab.index == 1) {
this.$nextTick(() => {
this.draw3()
this.draw4()
})
} else {
this.$nextTick(() => {
this.draw5()
this.draw6()
})
}
}