echarts有数据展示,没有数据则清空数据-集团平台

一、需求 如果有数据则根据数据进行柱状图的展示,如果没有数据则清空

    if(this.chart){
       this.chart.dispose()
       this.chart= null
    }

1、获得接口返回的对象长度

      let orgList = []
      this.$store.getters.orgList.forEach(r => {
      if(r.isStatiData == true){
          orgList.push(r)
        }
      });
      let year = this.routerData.slice(0,4)
      let month = this.routerData.slice(4,6)
      this.showData=true;
      let params = {
        repYear:year,
        repMonth:month,
      };
      findDataByOperation(params).then(res=>{
        let count =Object.keys(res.data).length
        let reportList=[]
        if(count > 0){
          reportList= res.data.fillInData
          this.showData = []
          for(let i = 0; i < reportList.length; i++){
            let fd = reportList[i]
            let sd = {
              orgId: fd.orgId,
              name: '',
              totalCount: fd.gunFillInTotalCount,
              totalBullCount: fd.bullCount
            }
            this.showData.push(sd)
          }
          // 公司名赋值
          for(let i = 0; i < this.showData.length; i++) {
            let d = this.showData[i]
            for(let j = 0; j < orgList.length; j++) {
              let o = orgList[j]
              if(d.orgId == o.orgId) {
                d.name = o.orgShortName
                break
              }
            }
          }
          // 生成柱状图
          let name = []
          let totalCount = []
          let totalBullCount = []
          for(let i = 0; i < this.showData.length; i++) {
            let d = this.showData[i]
            name.push(d.name)
            totalCount.push(d.totalCount)
            totalBullCount.push(d.totalBullCount)
            if(i == this.showData.length - 1) {
              // 生成柱状图
              this.initChart(name, totalCount, totalBullCount)
            }
          }
        }else{
          if(this.chart){
            this.chart.dispose()
            this.chart= null
          }
        }
      })

  

 

posted @ 2024-11-26 15:40  flyComeOn  阅读(35)  评论(0编辑  收藏  举报