echarts的getZr().on事件获取图表数据信息

初始化echarts实例
my2Chart = echarts.init(myChartas);
直接C
my2Chart.getZr().on("click", (params) => {
    let pointInPixel = [params.offsetX, params.offsetY];
    if (my2Chart?.containPixel("grid", pointInPixel)) {
      let pointInGrid = my2Chart.convertFromPixel(
        {
          seriesIndex: 0,
        },
        pointInPixel
      );
      let xIndex = pointInGrid[0]; //索引
      let handleIndex = Number(xIndex);
      let seriesObj = my2Chart.getOption(); //图表object对象
      var op: any = my2Chart.getOption();
      //获得图表中点击的列
      var month = op.xAxis[0].data[handleIndex]; //获取点击的列名
      console.log(month);
      console.log(handleIndex, seriesObj);
    }
  });

 

posted @ 2024-08-07 14:40  QinHaoRan  阅读(411)  评论(0)    收藏  举报