GraphView change x and y axis ranges
Asked Answered
M

1

6

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

Maxine answered 19/11, 2015 at 19:46 Comment(0)
K
19

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 :)

Keijo answered 27/2, 2016 at 4:38 Comment(2)
Thx! I had the setMinY call but didn't know to use (or even look for) the setYAxisBoundsManual call.Spectrum
@RajeshKoshti Do you have added the last two lines in your code?Ciborium

© 2022 - 2024 — McMap. All rights reserved.