1、安装npm install echarts --save
2、引入(全局)
// 引入 echarts
import * as echarts from 'echarts'
Vue.prototype.$echarts = echarts
3、基础创建代码
const chartDom = document.getElementById('bar')
this.barChart = echarts.init(chartDom)
let option = {}
option && this.barChart.setOption(option)
4、缩放自适应
mounted() {
this.$nextTick(() => {
// setTimeout(this.getTrendData(), 2000)
})
window.onresize = this.debounce(this.reDrawGraph)
},
debounce(fn) {
let timer = null // 借助闭包
return function () {
if (timer) {
clearTimeout(timer)
}
timer = setTimeout(fn, 1000) // 简化写法
}
},
reDrawGraph() {
this.barChart.resize()
}