aChartEngine: getting coordinates of any point on

2019-08-14 02:22发布

I am using achartengine to display line graphs.And i am stuck at trying to get the coordinates of a point on touch (not the coordinates on the line graph but anywhere in the graph area). so i think getSeriesAndPointForScreenCoordinate(...) wont help in this case.

Any suggestions?

2条回答
放我归山
2楼-- · 2019-08-14 03:00

try using this code :

myXYPlot.setOnTouchListener(new OnTouchListener() {

        @Override
        public boolean onTouch(View v, MotionEvent event) {
            // TODO Auto-generated method stub

            switch (event.getAction()) {
            case MotionEvent.ACTION_MOVE:
                displaycoordinates(event);
                break;

            case MotionEvent.ACTION_DOWN:
                displaycoordinates(event); 
                break;                  
            default:
                break;
            }
            return true;
        }           
    });              
}

where displaycoordinates() is defined below:

public void displaycoordinates(MotionEvent event) {
    // TODO Auto-generated method stub

    float x = event.getX();
    float y = event.getY();

    PointF point = new PointF(x,y);

    NumberFormat nf = new DecimalFormat("#0.00");

    Double j = getXval(x);
    String xval = nf.format(j);

    Double k = getYval(y);
    String yval = nf.format(x);

    if(j>=condition1 && k>=condition2 && j<=condition3 && k<=condition4)
    {
        toast = Toast.makeText(getApplicationContext(), xval+"xval"+yval+" yval", 0);
        toast.show();
    }

}
查看更多
女痞
3楼-- · 2019-08-14 03:19

If you have the screen coordinates point then you can just call chartView.toRealPoint() in order to get the real data coordinate values.

查看更多
登录 后发表回答