lilei 4 rokov pred
rodič
commit
dabdfba83e

+ 25 - 7
src/components/Echarts/bar.vue

@@ -28,11 +28,6 @@ export default {
         return []
       }
     },
-    // y轴坐标最大值
-    yMax: {
-      type: [Number, String],
-      default: 100
-    },
     // y轴坐标单位
     yUnit: {
       type: String,
@@ -116,12 +111,14 @@ export default {
       this.dom.resize()
     },
     pageInit () {
+      const that = this
       const legend = this.seriesData.map(_ => _.name)
       this.$nextTick(() => {
         const keys = this.value.map(item => (item = item.name))
         const values = this.value.map(item => (item = item.value))
         const xAxisData = this.value.length ? keys : this.xAxisData
         const seriesData = this.value.length ? values : this.seriesData
+        const yMax = this.getYMax(this.seriesData) // 计算最大值
         const option = {
           color: [this.color],
           title: {
@@ -158,7 +155,7 @@ export default {
           yAxis: {
             type: 'value',
             min: 0,
-            max: this.yMax,
+            max: yMax,
             axisLabel: {
               formatter: `{value} ${this.yUnit}`
             },
@@ -172,6 +169,7 @@ export default {
             containLabel: true
           }
         }
+        // 单柱图
         if (this.value.length) {
           option.series = [
             {
@@ -189,11 +187,31 @@ export default {
         } else {
           option.series = this.seriesData
         }
+        // 已创建的先销毁
+        if (this.dom) {
+          this.dom.dispose()
+        }
         this.dom = echarts.init(this.$refs.dom, 'tdTheme')
         this.dom.setOption(option)
-        this.dom.resize() // 解决首次加载宽度超出容器bug
+        // 更新y轴最大值
+        this.dom.on('legendselectchanged', function (params) {
+          // console.log(params, that.seriesData, 'legendselectchanged')
+          const data = that.seriesData.filter(item => params.selected[item.name])
+          option.yAxis.max = that.getYMax(data)
+          that.dom.setOption(option)
+        })
+        // 解决首次加载宽度超出容器bug
+        this.dom.resize()
         on(window, 'resize', this.resize)
       })
+    },
+    // 计算y轴最大值
+    getYMax (data) {
+      let max = []
+      data.map(item => {
+        max = max.concat(item.data)
+      })
+      return Math.max.apply(null, max)
     }
   },
   mounted () {

+ 25 - 9
src/components/Echarts/line.vue

@@ -32,11 +32,6 @@ export default {
         return []
       }
     },
-    // y轴坐标最大值
-    yMax: {
-      type: Number,
-      default: 100
-    },
     // y轴坐标单位
     yUnit: {
       type: String,
@@ -95,7 +90,8 @@ export default {
     return {
       dom: null, // echarts实例对象
       isShowZoom: false, // 是否展示滚动条
-      xZoomEnd: 100 // x轴滚动条结束位置
+      xZoomEnd: 100, // x轴滚动条结束位置
+      yMax: 1000 // y轴最大值
     }
   },
   methods: {
@@ -103,10 +99,12 @@ export default {
       this.dom.resize()
     },
     pageInit () {
+      const that = this
       const legend = this.seriesData.map(_ => _.name)
       this.$nextTick(() => {
         const xAxisData = this.value ? Object.keys(this.value) : this.xAxisData
         const seriesData = this.value ? Object.values(this.value) : this.seriesData
+        const yMax = this.getYMax(this.seriesData) // 计算最大值
         const option = {
           color: [this.color],
           title: {
@@ -147,7 +145,7 @@ export default {
           yAxis: {
             type: 'value',
             min: 0,
-            max: this.yMax,
+            max: yMax,
             axisLabel: {
               formatter: `{value} ${this.yUnit}`
             },
@@ -168,15 +166,33 @@ export default {
             }
           }]
         } else {
-          // console.log(this.seriesData, '111111111')
           option.series = this.seriesData
         }
-        // console.log(option.series, 'ppppppp')
+        // 已创建的先销毁
+        if (this.dom) {
+          this.dom.dispose()
+        }
         this.dom = echarts.init(this.$refs.dom, 'tdTheme')
         this.dom.setOption(option)
+        // 更新y轴最大值
+        this.dom.on('legendselectchanged', function (params) {
+          // console.log(params, that.seriesData, 'legendselectchanged')
+          const data = that.seriesData.filter(item => params.selected[item.name])
+          option.yAxis.max = that.getYMax(data)
+          that.dom.setOption(option)
+        })
+        // 重置图标大小
         this.dom.resize()
         on(window, 'resize', this.resize)
       })
+    },
+    // 计算y轴最大值
+    getYMax (data) {
+      let max = []
+      data.map(item => {
+        max = max.concat(item.data)
+      })
+      return Math.max.apply(null, max)
     }
   },
   mounted () {

+ 7 - 23
src/views/cleanManage/statisticalReport.vue

@@ -44,7 +44,6 @@
           style="height: 300px;"
           color="#6C6FBE"
           ref="chartLine"
-          :yMax="maxClearnData"
           yUnit="kg"
           :xAxisRotate="resize"
           :xAxisData="XdaysData"
@@ -78,7 +77,6 @@
               style="height: 300px;"
               color="#6C6FBE"
               :xAxisRotate="resize"
-              :yMax="maxHswType"
               yUnit="kg"
               :xAxisData="XdaysData1"
               :seriesData="hswTypeBarData"
@@ -93,7 +91,6 @@
               style="height: 300px;"
               color="#6C6FBE"
               yUnit="kg"
-              :yMax="maxHswType"
               :xAxisRotate="resize"
               :xAxisData="XdaysData1"
               :seriesData="hswTypeLineData"
@@ -267,8 +264,6 @@ export default {
       currentTabChart: 'tab1', // 洗车类型详情数据与变化趋势的tab 默认展示详情数据
       XdaysData: [], // 图表X轴时间集合
       XdaysData1: [],
-      maxHswType: 100000,
-      maxClearnData: 100000,
       // 各类型占比
       washTypePieColor: ['#ffaa00', '#ff5500', '#00aaff', '#ff55ff', '#1dc5d4', '#8465c7', '#00ffff'],
       couponColor: ['#ffaa00', '#ff5500', '#00aaff', '#ff55ff', '#1dc5d4', '#8465c7', '#00ffff'],
@@ -392,7 +387,7 @@ export default {
       this.beginDate = quickType[this.curentType][0].format('YYYY-MM-DD')
       this.endDate = quickType[this.curentType][1].format('YYYY-MM-DD')
       console.log(this.searchForm.queryWord, '1111111')
-	  this.resetChartsData()
+	    this.resetChartsData()
       this.getPageData()
     },
     // 重置图表数据
@@ -412,9 +407,9 @@ export default {
 	  // 重置清运量趋势图表数据
       this.clearnChartData[0].data = []
       this.clearnChartData[1].data = []
-	  // 重置各回收物类型清运数据
-	  this.hswTypeBarData.map(item => item.data = [])
-	  this.hswTypeLineData.map(item => item.data = [])
+      // 重置各回收物类型清运数据
+      this.hswTypeBarData.map(item => item.data = [])
+      this.hswTypeLineData.map(item => item.data = [])
     },
     // 根据查询条件获取所有数据
     getPageData () {
@@ -443,20 +438,15 @@ export default {
         if (res.status == 200) {
           const a = res.data.cleanReportData
           const b = res.data.deliveryReportData
-          const max = []
-          for (var key in a) {
+          for (const key in a) {
             const val = Number(a[key] / 1000).toFixed(2)
             this.clearnChartData[0].data.push(val)
-            max.push(val)
           }
-          for (var key in b) {
+          for (const key in b) {
             this.XdaysData.push(key)
             const val = Number(b[key] / 1000).toFixed(2)
             this.clearnChartData[1].data.push(val)
-            max.push(val)
           }
-          // 计算最大值
-          this.maxClearnData = Math.max.apply(null, max)
           this.isNoData = false
         } else {
           this.isNoData = true
@@ -479,10 +469,9 @@ export default {
           for (const key in data) {
             this.XdaysData1.push(key)
           }
-
           this.hswTypeBarData = this.formAtGroupDateAndRubbishType(data, this.hswTypeBarData)
           this.hswTypeLineData = this.formAtGroupDateAndRubbishType(data, this.hswTypeLineData)
-		  this.isNoData1 = false
+          this.isNoData1 = false
         } else {
           this.isNoData1 = true
         }
@@ -490,7 +479,6 @@ export default {
     },
     // 格式化数据
     formAtGroupDateAndRubbishType (data, obj) {
-      const max = []
       obj.map(item => {
         const ret = []
         for (const key in data) {
@@ -498,13 +486,9 @@ export default {
           const row = leve2[item.code]
           const val = row ? Number(row.cleanWeight / 1000).toFixed(2) : 0
           ret.push(val)
-          max.push(val)
         }
         item.data = ret
       })
-      // 获取最大值
-      this.maxHswType = Math.max.apply(null, max)
-      console.log(this.maxHswType)
       return obj
     }
   },