angular 实现 echarts 拖动区域进行放大 方法

  • 实现逻辑:

  1.通过鼠标摁下事件  和弹出事件  获取x轴的index  之后去x轴的list中去获取两个坐标点 

  2.之后将这两个数据作为参数  传到后台更新数据

  3.记录下来这两个坐标点 放到list中  在前台提供向前一步和向后一步的按钮  实现回退功能

  4.需要注意的是:需要在myChart初始话之后再添加事件还有就是避免重复添加事件  只在mychart第一次初始化的时候才给他添加鼠标点击事件  否则会导致加载很多个事件

  •  angular代码:

       

    myChart.setOption(option,true);
            if(flag==0){
                flag++;
                    console.log("点击事件加载")

                var x_start;
                    myChart.getZr().on('mousedown',function(params){
                         const pointInPixel= [params.offsetX, params.offsetY];
                             if (myChart.containPixel('grid',pointInPixel)) {
                             var pointInGrid=myChart.convertFromPixel({seriesIndex:0},pointInPixel);
                           var xIndex=pointInGrid[0]; 
                           x_start= Math.round(option.series[0].data[xIndex*2][0]);
                         console.log("进入鼠标点击",xIndex);
                         console.log("进入鼠标点击",option.series[0].data[xIndex*2][0]);

                         }
                    });
                    myChart.getZr().on('mouseup',function(params){
                         const pointInPixel= [params.offsetX, params.offsetY];
                             if (myChart.containPixel('grid',pointInPixel)) {
                             var pointInGrid=myChart.convertFromPixel({seriesIndex:0},pointInPixel);
                           var xIndex=pointInGrid[0]; 
                           if(parseInt(x_start)<parseInt( Math.round(option.series[0].data[xIndex*2][0]))){
                               $scope.depth_start = x_start;
                                $scope.depth_end =  Math.round(option.series[0].data[xIndex*2][0]);
                           }else{
                               $scope.depth_end= x_start;
                                $scope.depth_start  =  Math.round(option.series[0].data[xIndex*2][0]);  
                           }
                             var a={
                                     'depth_start':    $scope.depth_start,
                                     'depth_end':$scope.depth_end
                             };                           
                           $scope.depth_data.push(a)
                           $scope.index+=1;
                           if($scope.depth_data.length==2){
                               $scope.depth_data_Judge=1;  
                           }else{
                               $scope.depth_data_Judge=1; 
                           }
                            $scope.createChart();
                           
                         }
                    });
            }
              });

 

转载于:https://www.cnblogs.com/Mr-yl/p/10571624.html

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值