echart 柱状图 整条 点击事件

chart.on

chart.on("click", function (params) {
    
    
    console.log(params.dataIndex);
});

chart.on 点击事件只能接收有数据部分的点击事件, 柱子上方无法响应, 没有数据的柱子无法响应.

chart.getZr().on

chart.getZr().on('click', (params) => {
    
    
    const pointInPixel = [params.offsetX, params.offsetY];
    if (chart.containPixel('grid', pointInPixel)) {
    
    
        let xIndex = chart.convertFromPixel({
    
    seriesIndex: 0}, [params.offsetX, params.offsetY])[0];
    }
});

chart.getZr().on 点击整条柱形区域都可以响应点击

猜你喜欢

转载自blog.csdn.net/MAIMIHO/article/details/108618285