androidgraphingandroid-graphviewdatapoint

Android - Get GraphView datapoint x y location


I'm using jjoe64's awesome GraphView for Android. At the moment I'm trying to determine 2 things:

  1. Is it possible, once plotted, to get a DataPoint's x,y location values?
  2. Also, is it possible to get that location in the onTap call?

I'm trying to show a custom view just above the data point (tapped or otherwise); hence the reason I need it's coordinates. I know how to get the x,y position of a user touch, but the issue is I also need the value from the datapoint.

From what I can tell the DataPoint and DataPointInterface do not have an accessible x,y location value - only x,y double values (non-location related).

I was hoping for something like:

    DataPoint p = series.getPoint(n);
    int x = p.getXLocation();
    int y = p.getYLocation();

Where n is either the exact position in the series (like getting something from an ArrayList) or n represents the non-location x value given to the DataPoint upon creation (new DataPoint(double x, double y)).

Has anyone else using this library solved this? Any help would be much appreciated. Thank you!


Solution

  • I ended up subclassing BaseSeries and basically doing a complete replication of LineGraphSeries with the exception of making some of those protected functions public. This gave me the ability to keep track of datapoints and their PointF's in a Map, then look up PointF's based on their corresponding datapoint.