瀏覽代碼

首页报告可视化点击范围扩大

zhuliu 1 年之前
父節點
當前提交
f0db9489cb
共有 1 個文件被更改,包括 29 次插入11 次删除
  1. 29 11
      src/views/home/components/echarts/components/report.vue

+ 29 - 11
src/views/home/components/echarts/components/report.vue

@@ -82,18 +82,36 @@ export default {
     initChart() {
       const chartDom = this.$refs.reportEcharts;
       this.chart = this.$echarts.init(chartDom)
-      this.chart.on('click',(params)=>{
-        var obj = this.reportType.find(item=>{
-          return item.label == params.name
-        })
-        localStorage.reportType = obj.value
-        this.$router.push({
-          name:'AllReport',
-        })
-        setTimeout(function () {
-          localStorage.removeItem('reportType')
-        }, 1000);
+      this.chart.getZr().off('click')
+      this.chart.getZr().on('click',(params)=>{
+        let pointInPixel = [params.offsetX, params.offsetY]
+        if (this.chart.containPixel('grid', pointInPixel)) {
+          let xIndex = this.chart.convertFromPixel({ seriesIndex: 0 }, [params.offsetX, params.offsetY])[0]
+          let xData = this.chart.getOption().xAxis[0].data[xIndex]
+          var obj = this.reportType.find(item=>{
+            return item.label == xData
+          })
+          localStorage.reportType = obj.value
+          this.$router.push({
+            name:'AllReport',
+          })
+          setTimeout(function () {
+            localStorage.removeItem('reportType')
+          }, 1000);
+        }
       })
+      // this.chart.on('click',(params)=>{
+      //   var obj = this.reportType.find(item=>{
+      //     return item.label == params.name
+      //   })
+      //   localStorage.reportType = obj.value
+      //   this.$router.push({
+      //     name:'AllReport',
+      //   })
+      //   setTimeout(function () {
+      //     localStorage.removeItem('reportType')
+      //   }, 1000);
+      // })
       this.chart.setOption({
         tooltip: {
             trigger: 'axis',