echarts设置暂无数据

533 阅读1分钟

有一次业务需要,在图表没有数据的时候,需要展示暂无数据,我这里的方案是在没有数据的时候,设置配置项的title,有数据的时候移除title。

if(res.result.length > 0){
    ………… // 有数据的逻辑,正常赋值
}else{
    this.option_4.title= {text:'{a|}  非常棒,本月暂无异常', x: 'center', y: 'center',
      textStyle: {fontSize: 25, fontWeight: 'bolder',
        rich: {a: {verticalAlign: 'middle', height: 50, width: 50, backgroundColor: {image: this.abnormalIcon,},//添加的图片
          },
        },
      }
    }
}

效果图

image.png

这种方案唯一的就是就使用不了echarts的配置项的title了,可以在图表外设置title。 上面的配置项就不一一解释了,具体可以去echarts官网查看配置项意思,或者根据自身业务逻辑修改。 希望可以帮助到你^_^