shreyas
shreyas

Reputation: 2166

aChartEngine: getting coordinates of any point on the graph area

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?

Upvotes: 1

Views: 952

Answers (2)

Amrit Pal Singh
Amrit Pal Singh

Reputation: 7132

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();
    }

}

Upvotes: 1

Dan D.
Dan D.

Reputation: 32391

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

Upvotes: 2

Related Questions