为echarts图表添加全局加载动画函数和自适应效果

全局加载动画函数:

//showLoading做成循环,使用时可以写成数组形式批量添加,否则只能添加单个图表
Vue.prototype.showLoading = function showLoading(chart) {
  for (let i of chart){
    i.showLoading({
      text: '',
      color: '#5CADEE',
      textColor: '#fff',
      maskColor: 'transparent',
      zlevel: 0
    });
  }
};

Vue.prototype.hideLoading = function hideLoading(chart) {
  chart.hideLoading({
    text: '',
    color: '#5CADEE',
    textColor: '#fff',
    maskColor: 'transparent',
    zlevel: 0
  });
};

//调用方式示例:                
this.showLoading([this.chart1, this.chart2, this.chart3, this.chart4, this.chart5])
this.hideLoading(this.chart1)

图表随屏幕变化自适应:

window.addEventListener('resize', () => {
                this.chart1.resize();
                this.chart2.resize();
                this.chart3.resize();
                this.chart4.resize();
                this.chart5.resize();
                this.chart6.resize();
                this.map.resize();
            }, {passive: true}) //是否取消阻止默认行为(preventDefault()) 
           

初始化echarts:

this.chart1 = this.$echarts.init(this.$refs.chart1)
this.chart1.setOption(option)
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值