Search code examples
androidandroid-graphview

How to get co-ordinates values in graphview?


i'm using

GraphViewSeries g1 = new GraphViewSeries("",
    new GraphViewSeriesStyle(Color.WHITE, 1/3),new GraphViewData[] {
            new GraphViewData(-5,0d),
            new GraphViewData(5,0d),

    });

GraphViewSeries g2 = new GraphViewSeries("",
    new GraphViewSeriesStyle(Color.WHITE, 1/3),new GraphViewData[] {
            new GraphViewData(0,-5d),
            new GraphViewData(0,5d),

    });

GraphViewSeries g3 = new GraphViewSeries("",
    new GraphViewSeriesStyle(Color.WHITE, 1/3),new GraphViewData[] {
            new GraphViewData(-5,-5d),
            new GraphViewData(5,-5d),

    });

    graphView.getGraphViewStyle().setNumVerticalLabels(11);
    graphView.getGraphViewStyle().setNumHorizontalLabels(11);
    graphView.setManualYAxisBounds(5, -5);
    graphView.setViewPort(-5,10); 



    int screenX = (int)event.getX();
    int screenY =(int) event.getY();

I set the labels 11 for both horizontal and vertical .. using this getX() and GetY() method I got the values like 414,403 and etc..it shows the values beyond the i'm mentioned values how can i get x,y values like 1,0 and -1,3 etc.. that means i given GraphViewData..


Solution

  • For setting up y axies you can do

    graphView.setManualYAxisBounds(5, -5); // min=-5, max=5
    graphView.getGraphViewStyle().setNumVerticalLabels(11); // will have 11 y axis lables
    

    the above code will make y axis with values -5, -4, -3, .... , 4, 5. (and they will remain like this always).

    and for x axis use

    setViewPort(-5, 1); // start position=-5, size=1
    

    above code starts will make x axis start from -5 with size of 1.