echarts柱状图点击阴影部分触发事件

在很多时候我们的柱状图分布不均匀,有些柱高可能会很小,如果通过myChart.on('click',function(){})来促发事件,可能在点击的时候不好操作,因为这个click事件是绑定在各个serie上的,也就是单个柱子上,可以通过param参数获取点击的serie信息。但是如果要满足在柱高非常小的时候,也能有点击事件,我们可以对在整个对serie的阴影部分绑定。如下:

myChart.getZr().on('click',function(params){
                const pointInPixel= [params.offsetX, params.offsetY];
                if (cityChart.containPixel('grid',pointInPixel)) {
                    var xIndex=cityChart.convertFromPixel({seriesIndex:0},[params.offsetX, params.offsetY])[0];
                        function(xIndex){
                             ...
                         };
                }
            });    
原文地址:https://www.cnblogs.com/guozhigang/p/10141391.html