MPAndroidChart: How do I get the corresponding chart x-value for a pixel point?

后端 未结 1 1780
死守一世寂寞
死守一世寂寞 2020-12-12 01:31

How can I obtain the corresponding x-axis value (xIndex) of a pixel point in a ScatterChart?

I have been looking through the source code of the library and I think t

相关标签:
1条回答
  • 2020-12-12 01:52

    Using MPAndroidChart 3.0.1

    I think the method you want is:

    public MPPointD getValuesByTouchPoint(float x, float y);
    

    Here's a snip from the javadoc:

    /**
     * Returns a recyclable MPPointD instance.
     * returns the x and y values in the chart at the given touch point
     * (encapsulated in a MPPointD). This method transforms pixel coordinates to
     * coordinates / values in the chart. This is the opposite method to
     * getPixelsForValues(...).
    

    To use it in your app, do something like this:

    MPPointD point = mChart.getTransformer(AxisDependency.LEFT).getValuesByTouchPoint(x,y);
    double xValue = point.x;
    double yValue = point.y;
    

    The parameters passed into the method (float x, float y) are your pixel co-ordinates that you want to be converted into x and y values in your chart.

    0 讨论(0)
提交回复
热议问题