//1、安装ECharts
npm install echarts --save
//2、导入ECharts
import * as echarts from 'echarts'
//3、创建图表容器
mounted() {
// 初始化图表
let chart = echarts.init(this.$refs.chartContainer)
// 设置图表配置项
let option = {
// ...
}
// 设置图表配置项并刷新图表
chart.setOption(option)
}
//4、设置图表配置项
mounted() {
// 初始化图表
let chart = echarts.init(this.$refs.chartContainer)
// 设置图表配置项
let option = {
title: {
text: '柱状图示例'
},
tooltip: {},
xAxis: {
data: []
},
yAxis: {},
series: [{
name: '访问量',
type: 'bar',
data: []
}]
}
// 设置图表配置项并刷新图表
chart.setOption(option)
}
//5、销毁图表
beforeDestroy() {
// 销毁图表
let chart = this.$refs.chartContainer.querySelector('div.echarts')
chart && chart.dispose()
}