防股票折线图十字定位(achartengine)

   防股票折线图十字定位(achartengine)

  * @param context
     * @param view4:曲线view
     * @param x:曲线x轴集合
     * @param marginLeft:移动x轴左边距
     * @param marginBottom:移动x轴下边距
     * @param marginLeftY:移动y轴左边距
     * @param marginBottomY:移动y轴左边距
     * @param mChart
     * @param tvXY:显示textview
     * @param lineWidth:xy线宽
     * @param mPopupView:移动y轴视图
     * @param mPopupView2:移动x轴视图
     * @param type:二分查询类型

public static void markXY(final Context context, final GraphicalView view4, final List<double[]> x, final int marginLeft, final int marginBottom, final int marginLeftY, final int marginBottomY, final XYChart mChart, final TextView tvXY, final int lineWidth, final View mPopupView, final View mPopupView2, final int type){

        
        OnTouchListener chartViewOnTouchListener = new OnTouchListener() {
            PopupWindow mPopupWindow=null;
            PopupWindow mPopupWindow2=null;
            public boolean onTouch(View v, MotionEvent event) {
                switch (event.getAction()) {
                case MotionEvent.ACTION_DOWN:
                    mPopupWindow = new PopupWindow(mPopupView,lineWidth, view4.getHeight());
                    mPopupWindow2 = new PopupWindow(mPopupView2,view4.getWidth(), lineWidth);
                    break;
                case MotionEvent.ACTION_MOVE:
//                    //自定义设置xy
                    //获取点击位置屏幕xy
                    float screenX = event.getX();
                    float screenY = event.getY();
                    //装换为图标xy
                    double[] realPoint = mChart.toRealPoint(screenX, screenY);
                    XYMultipleSeriesDataset dataset = mChart.getDataset();
                    XYSeries seriesAt = dataset.getSeriesAt(0);
                    if(x!=null&&x.size()>0){
                    int index=binarySearch(x.get(0), realPoint[0],type);
                    if(index<x.get(0).length){
                    Log.i("TAG", "dataset:"+seriesAt.getX(index)+";"+seriesAt.getY(index));
                    double[] screenPoint2 = mChart.toScreenPoint(new double[]{seriesAt.getX(index),seriesAt.getY(index)});
                    double[] screenPoint = mChart.toScreenPoint(new double[]{0,0});
                    int toBottom=(int) (view4.getHeight()-screenPoint[1]);
                    int toLeft=(int)(view4.getWidth()-screenPoint[0]);
                    if(seriesAt.getY(index)==0.0){
                        tvXY.setText("");
                    }else{
                       tvXY.setText("x:"+seriesAt.getX(index)+" y:"+seriesAt.getY(index));
                    }
                    Log.i("TAG", "screenPoint2:"+screenPoint2.length+":"+screenPoint2[0]+";"+screenPoint2[1]);
                    if (mPopupWindow.isShowing()) {
                        mPopupWindow.update((int)screenPoint2[0]+dip2px(context, marginLeftY),dip2px(context, marginBottomY)+toBottom, lineWidth,view4.getHeight()-toBottom);
                        mPopupWindow2.update(dip2px(context, marginLeft),view4.getHeight()-(int)screenPoint2[1]+dip2px(context, marginBottom), view4.getWidth(),lineWidth);
                    } else {
                        mPopupWindow.showAtLocation(view4,Gravity.BOTTOM|Gravity.LEFT, (int)screenPoint2[0]+dip2px(context, marginLeftY)+toLeft,dip2px(context, marginBottomY));
                        mPopupWindow2.showAtLocation(view4,Gravity.BOTTOM|Gravity.LEFT, dip2px(context, marginLeft),view4.getHeight()-(int)screenPoint2[1]+dip2px(context, marginBottom));
                    }    
                    }
                    }
                    break;
                case MotionEvent.ACTION_UP:
                    //隐藏定位轴
                    if (mPopupWindow != null) {
                        if (mPopupWindow.isShowing()) {
                            mPopupWindow.dismiss();
                        }
                        mPopupWindow = null;
                    }
                    if (mPopupWindow2 != null) {
                        if (mPopupWindow2.isShowing()) {
                            mPopupWindow2.dismiss();
                        }
                        mPopupWindow2 = null;
                    }
                    break;    
                }
                return false;
            }
        };
        view4.setOnTouchListener(chartViewOnTouchListener);
        view4.setId(0);
    }
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值