Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
45
Chart Cursor
posted

Hi,

I use  setOnSeriesCursorMoveListener(this); . I can perfectly get the closest item to the point in onSeriesCursorMove from chartCursorEvent.

How can I get the Y coordinate of the cursor's location where user holds the finger ? And how can I hide the native gray cursor lines of chart ?

Thank you

  • 34430
    Offline posted

    Hello Baris,

    It doesn't appear that from the listener attached to the setOnSeriesCursorMoveListener event that you can actually get the exact Y coordinate of the cursor location, but you can get the item's Y point from the event arguments of that event. The ChartCursorEvent element that exists in the parameters for the onSeriesCursorMove override has a getItem() method, which is likely what you are using to get the closest item to the point. Using this with the getSeries() method of that same object, you can check the value path of your series, and find the y value of the item corresponding to that value path.

    For a more exact y coordinate, I would recommend that you actually use a separate event, and hook a new onTouchListener to the DataChartView. Doing this will net you a MotionEvent in the onTouch override, which has a getY() method to get the actual screen position Y coordinate. If you run this through the getUnscaledValue method of your y axis, you can get a point on your chart that is relative to that screen position of the getY() method. The code for this could look like the following:

    chart.setOnTouchListener(new View.OnTouchListener() {
                @Override
                public boolean onTouch(View view, MotionEvent motionEvent) {

                    DataChartView v = ((DataChartView) view);

                    NumericYAxis y = (NumericYAxis) v.getAxisAt(1);

                    double point = motionEvent.getY();

                    double unscale = y.getUnscaledValue(point, v.getActualWindowRect(), v.getViewportRect());
                    Log.d("Unscale", ((Double) unscale).toString());
                    return true;
            }
    });

    Regarding the native gray cursor lines on the DataChartView, I am assuming you are referring to the horizontal "grid" lines that exist on the chart by default? You can hide these by utilizing the setMajorStroke method of your yAxis and setting it to a new SolidColorBrush with a color of Transparent. The code for this would look like the following:

    yAxis.setMajorStroke(new SolidColorBrush(Color.TRANSPARENT));

    I hope this helps you. Please let me know if you have any other questions or concerns on this matter.

    Sincerely,
    Andrew
    Associate Developer