echart数据太少,灰色背景添加点击事件

115 阅读1分钟

image.png 如图,使整个灰色背景都可以触发点击事件。

      this.mainChart.getZr().on('click', (params) => {
        console.log(params)
        const pointInPixel = [params.offsetX, params.offsetY]
        if (this.mainChart.containPixel('grid', pointInPixel)) {
          const pointInGrid = this.mainChart.convertFromPixel({ seriesIndex: 0 }, pointInPixel)
          const xIndex = pointInGrid[0]
          console.log(xIndex, 'xindex', this.options.xAxis[0].data)
          this.mainChart.resize()
          that.getStatisticLabelEntList(this.options.xAxis[0].data[xIndex])
        }
      })

输出如下,可以拿到相应的数据。 040135b121501b345a0e814e47063c0.png