WishMeLz

生活其实很有趣

echarts 点击事件

通用点击事件

    myChart.on('click', function (params: any) {
        if (params.componentType == "xAxis") {
          
        }
        // if (params.componentType == "series") {
        // }
    })

2023-07-13T09:42:41.png

不是数据的地方点击不触发

    myChart.getZr().on('click', (params: any) => {
        if (myChart.containPixel('grid', pointInPixel)) {
        //点击第几个柱子
        let pointInGrid = myChart.convertFromPixel({ seriesIndex: 0 }, pointInPixel)
        let xIndex = pointInGrid[0]
        // y轴数据的索引
        let yIndex = pointInGrid[1]
        if (xIndex == '-0' || xIndex >= 0) {
         
        } else {
            
        }
      } 
    })