echart点击事件

myChart.getZr().on('mouseover', params => {
  let pointInPixel = [params.offsetX, params.offsetY]
  if (myChart.containPixel('grid', pointInPixel)) {
    //点击第几个柱子
    let pointInGrid = myChart.convertFromPixel({ seriesIndex: 0 }, pointInPixel)
    // 也可以通过params.offsetY 来判断鼠标点击的位置是否是图表展示区里面的位置
    // 也可以通过name[xIndex] != undefined,name是x轴的坐标名称来判断是否还是点击的图表里面的内容
    // x轴数据的索引
    let xIndex = pointInGrid[0]
    let xstr = this.allDataMsg[xIndex];
    //console.log(xstr);//然后弹框回显数据,并可以更新备注信息
  }
})

猜你喜欢

转载自blog.csdn.net/qq_40390762/article/details/127821788