echart 防止多次渲染 无数据时显示暂无数据 vue3
//基于准备好的dom,初始化echarts实例
const barDOM: any = ref();
var myChart: any;
let echartNull: any = null;
// 渲染echart
const init_chart = () => {
if (myChart != null && myChart != "" && myChart != undefined) {
    myChart .dispose(); //销毁
 }
 myChart = echarts.init(barDOM.value, echartNull, { locale: "ZH" });
 var option;
if (xAxis.length == 0) {//判断x轴的数据是否为空
  //空数据    
  option = {
      title: {
        text: "暂无数据",
        x: "center",
        y: "center",
        textStyle: {
          fontSize: 16,
          color: "#ffffff",
          fontWeight: "normal",
        },
      },
    };
}else {
option = {}
}
 myChart.setOption(option);
  window.onresize = function () {
    myChart.resize();
  };
}
    !!
                    
                
                
            
        
浙公网安备 33010602011771号