echarts监听点击(空白处)事件,echarts监听滑动事件

    技术2022-07-11  77

    echarts监听点击(空白处)事件,echarts监听滑动事件

    利用getZr()属性获取滑动事件和点击事件,(需要支持es6,否则自行改写)

    let obj = document.getElementById(‘xxxxxxxxxxxxxxId’) if (!obj) return let myChart = echarts.init(obj) myChart.setOption(item.option) // 点击 myChart.getZr().on(‘click’, params => { const pointInPixel = [params.offsetX, params.offsetY] if (myChart.containPixel(‘grid’, pointInPixel)) { let xIndex = myChart.convertFromPixel({ seriesIndex: 0 }, [params.offsetX, params.offsetY])[0]; console.log(xIndex); } }) // 滑动 myChart.getZr().on(‘mousemove’, params => { const pointInPixel = [params.offsetX, params.offsetY] if (myChart.containPixel(‘grid’, pointInPixel)) { let xIndex = myChart.convertFromPixel({ seriesIndex: 0 }, [params.offsetX, params.offsetY])[0] alert(xIndex) } })

    Processed: 0.013, SQL: 12