解决echarts柱状图数量太少,点击事件不生效问题

20210428094354203.png (1001×753)

myChart4.getZr().on('click',function (params) {
  let pointInPixel= [params.offsetX,params.offsetY];
  if(myChart4.containPixel('grid',pointInPixel)){
    let pointInGrid=myChart4.convertFromPixel({seriesIndex: 0},pointInPixel);
    let xIndex=pointInGrid[0] //获取下标
  }
})

关闭echarts的点击事件,通过点击位置获取到xIndex为第几列,0代表第1列,然后通过这个去找到你本地的数据,完成点击效果.

猜你喜欢

转载自blog.csdn.net/weixin_60196946/article/details/131961457