堆疊圖 計(jì)算每列的總和

計(jì)算每列的總和
getGoldCharts() {
      this.goldChartLoading = true;
      saleWeightChart({
        start: this.queryParams.createdDateRange?.[0] ? this.queryParams.createdDateRange[0] + " 00:00:00" : '',
        end: this.queryParams.createdDateRange?.[1] ? this.queryParams.createdDateRange[1] + " 23:59:59" : ''
      }).then(({ code, data }) => {
        if (code == 0) {
          this.goldChart = this.echarts.init(document.getElementById('goldCharts'));
          var option = {
            tooltip: {
              trigger: 'axis',
              axisPointer: {
                type: 'shadow'
              }
            },
            title: {
              text: '黃金發(fā)貨量(克)',
            },
            grid:{
              left: '2%',
              right: '4%',
              bottom: '2%',
              containLabel: true
            },
            yAxis: {
              splitLine:{
                show:true,
                lineStyle:{
                  type:'dashed'
                }
              }
            },
            xAxis: {
              type: 'category',
              axisTick: {
                show: false,
              },
              axisLabel: {
                show: true,
                rotate: 30, //傾斜顯示
                interval: 0 // 顯示所有標(biāo)簽
              },
              data: data.map((item, did) => item.preDate)
            },
            dataZoom: [
              {
                id: 'dataZoomX',
                type: 'slider',
                xAxisIndex: [0],
                filterMode: 'filter',
                backgroundColor: "#C0C4CC",
                fillerColor: "#409EFF",
                borderColor: "#C0C4CC", // 設(shè)置邊框顏色
                height: 20,
                bottom: 3, // dataZoom-slider組件離容器下側(cè)的距離
              },
            ],
            color: ['#09BD3C', '#C0C4CC', '#FD5353', '#EBEEF5'],
            series: [
              {
                name: '待發(fā)貨',
                type: 'bar',
                stack: 'total',
                barWidth: '30%',
                data: data.map((item, did) => item.waitDeliveryGoldWeight),
              },
              {
                name: '已發(fā)貨',
                type: 'bar',
                stack: 'total',
                barWidth: '30%',
                data: data.map((item, did) => item.deliveryGoldWeight)
              },
              {
                name: '預(yù)警值',
                type: 'bar',
                stack: 'total',
                barWidth: '30%',
                data: data.map((item, did) => item.exceedGodlWeight)
              },
            ],
          };
          const series = option.series;
          series.push({
            name: '總計(jì)',
            type: 'bar',
            stack: 'y',    //注意與前面的stack屬性不同?。。。?            barWidth: '30%',
            label:{
              normal:{
                show:true,
                position:'top',
              }
            },
            color: 'rgba(0,0,0,0)',  //透明
            // 計(jì)算每列的總和
            data: data.map(item => item.waitDeliveryGoldWeight + item.deliveryGoldWeight + item.exceedGodlWeight),
            z: -1, // 隱藏在最底層
            barGap: '-100%',  //與堆疊柱條重合
          })
          this.goldChart.setOption(option);
        }
      }).finally(() => {
        this.goldChartLoading = false;
      });
    },
堆疊柱狀圖數(shù)據(jù)顯示在內(nèi)部的話,會(huì)把返回值為0的也展示出來(lái),所以需要單獨(dú)處理下
顯示在柱子里
series: [
              {
                name: '待發(fā)貨',
                type: 'bar',
                stack: 'total',
                barWidth: '30%',
                label:{
                  normal:{
                    show:true,
                    position:'inside',// 顯示在柱子里
                    // 這里處理下
                    formatter: function(params) {
                      return params.value > 0 ? params.value : '';
                    }
                  }
                },
                data: data.map((item, did) => item.waitDeliveryGoldWeight),
              },
            ],
注意

因?yàn)檫@里x軸只有一列堆疊柱狀圖,所以采用的是series.push這種方法,百度上查詢(xún)出來(lái)說(shuō)x軸只多列堆疊柱狀圖的話不能用此方法(待驗(yàn)證)
我這里的 預(yù)警值 是不包含在原有總計(jì)里面的,所以在總計(jì)這里把每個(gè)返回值都給加起來(lái)了。

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書(shū)系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容