Have you tried this?
SeriesSelection seriesSelection = view.getCurrentSeriesAndPoint();
double[] xy = view.toRealPoint(0);
Log.i(this.toString(), "OnClickListener" + xy[0] + "y:" + xy[1]);
or much better look at this example rows: 167-172
EDIT
Ok, try this, for each point in your dataset:
- Transform the real point to screen point
- Compute the distance from the touch event
- If the distance is less then a specified amount
(2*pointSize in this example) then grab the value and show your popup
What I don't like here is that, in the worst case, you've to iterate all the points...but i hope that this will give you some hints.
final XYChart chart = new LineChart(mDataset, mRenderer);
mChartView = new GraphicalView(this, chart);
mChartView.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
XYSeries series = mDataset.getSeriesAt(0);
for(int i = 0; i < series.getItemCount(); i++) {
double[] xy = chart.toScreenPoint(new double[] { series.getX(i), series.getY(i) }, 0);
double dx = (xy[0] - event.getX());
double dy = (xy[1] - event.getY());
double distance = Math.sqrt(dx*dx + dy*dy);
if (distance <= 2*pointSize) { //.pointSize that you've specified in your renderer
SeriesSelection sel =
chart.getSeriesAndPointForScreenCoordinate(new Point((float)xy[0], (float)xy[1]));
if (sel != null) {
Toast.makeText(XYChartBuilder.this, "Touched: " + sel.getValue(), Toast.LENGTH_SHORT).show();
}
break;
}
Log.i("LuS", "dist: " + distance);
}
return true;
}
});