Loading

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

假如使用echarts显示柱状图时,如果图形数据悬殊比较大,就会出现某些柱形比较长,有些会非常短。那么短的部分会比较难点击。

这时候,可以使用echarts提供的getZr来获取点击区域的位置,然后使用convertFromPixel转换当前位置对应的x轴索引或y轴索引。


this.myChart.getZr().off('click')  //最好加上

this.myChart.getZr().on('click', ({ offsetX, offsetY }) => {
  const pointInPixel = [offsetX, offsetY];
  if (this.myChart.containPixel('grid', pointInPixel)) {
    const [, yIndex] = this.myChart.convertFromPixel({ seriesIndex: 0 }, pointInPixel);
    // 逻辑代码
  }
});
posted @ 2020-11-26 11:55  shinebay  阅读(782)  评论(0编辑  收藏  举报