安装Echart依赖
npm install echarts -save
在main.js中引入
// 引入echarts
import echarts from 'echarts'
Vue.prototype.$echarts = echarts
在组件中使用
// 基于准备好的dom,初始化echarts实例 写在 mounted()里面
let sum_earnings = this.$echarts.init(
document.getElementById("sum_earnings")
);
this.drawLin( sum_earnings);
//写在methods方法里面封装然后在,在mounted()里面调用个人比较喜欢这种的写法,方便封装
drawLine: function(name) {
// 绘制图表
name.setOption({ '代码块(option里面的)' })
}
关于响应式
// 需要在mounted()方法里面初始化echarts实例之后调用
window.onresize = function() {
实例的名字.resize();
};
我用到的代码及注释
折线图
折线图.png
// 绘制图表
name.setOption({