Echarts点击事件

一. 普通点击事件

  1. 只有点击折线点或柱子等相应的地方才会触发click事件
  2. myChart.on('click', function (params) {
         me.clickDailyChart(params.name);
    });

    name: x轴的label

二. 精准点击事件

  1. 对整个图表的点击事件进行监听,通过点的坐标来找到数组下标,任何位置可触发点击事件
    this.myChart.getZr().on('click', function (param) {
            const pointInPixel = [
              param.offsetX,
              param.offsetY,
            ];
            if (me.myChart.containPixel('grid', pointInPixel)) {
              const index = me.myChart.convertFromPixel({seriesIndex: 0}, pointInPixel)[0];
              const op = myChart.getOption();
              const name = op.xAxis[0].data[index ];
              me.clickMyChart(param,index);
            }
          });

    通过point得到点击的坐标点x和y。

三. 其他点击事件

  1. 图例点击事件
    this.totalChart.on('legendselectchanged', legend => {
            me.clickTotalChart(legend);
          });

    取消点击:

    legend: {
      selectedMode:false,//取消图例上的点击事件
      data:[]
    }

     

  2. 各种点击事件

四. 取消点击事件

myChart.getZr().off('click');

有时因为嵌套关系,点击事件会触发冒泡,会执行两次点击事件,在点击事件之前加一个off事件,避免点击时发生二次调用的问题。

 

  • 4
    点赞
  • 21
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值