问题
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?
回答1:
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();
}
}
回答2:
If you have the screen coordinates point then you can just call chartView.toRealPoint()
in order to get the real data coordinate values.
来源:https://stackoverflow.com/questions/16566962/achartengine-getting-coordinates-of-any-point-on-the-graph-area