GraphView change x and y axis ranges

14,101

GraphView sets the axis range by default. What you wish to do is set the limits manually. After setting the ranges, you must tell the graphView to set the range as per your directive. This is how:

graph = (GraphView) findViewById(R.id.session_graph);
series = new LineGraphSeries<DataPoint>(new DataPoint[] {});
graph.addSeries(series);

graph.getViewport().setMinX(1);
graph.getViewport().setMaxX(50);
graph.getViewport().setMinY(2.0);
graph.getViewport().setMaxY(15.0);

graph.getViewport().setYAxisBoundsManual(true);
graph.getViewport().setXAxisBoundsManual(true);

Hope this helps and the answer is not too late :)

Share:
14,101
Brejuro
Author by

Brejuro

Updated on June 06, 2022

Comments

  • Brejuro
    Brejuro about 2 years

    I have a line graph that I add data to each time the user enters a number. The user enters a number 50 times, so I want the x axis to range from 1 to 50 in increments of 1. On the y axis, I want it to range from 2 - 15 (user enters a number between 2 and 15) in increments of 1. I'm really not sure how to do this, this is what I have:

        graph = (GraphView) findViewById(R.id.session_graph);
        series = new LineGraphSeries<DataPoint>(new DataPoint[] {});
        graph.addSeries(series);
    
        graph.getViewport().setMinX(1);
        graph.getViewport().setMaxX(50);
        graph.getViewport().setMinY(2.0);
        graph.getViewport().setMaxY(15.0);
    

    However, when I fire up my app, the x and y axis range from 0 - 2 in intervals of 0.5

  • Anne Gunn
    Anne Gunn almost 8 years
    Thx! I had the setMinY call but didn't know to use (or even look for) the setYAxisBoundsManual call.
  • Julian Schmuckli
    Julian Schmuckli about 7 years
    @RajeshKoshti Do you have added the last two lines in your code?