Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GraphView change x and y axis ranges

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

like image 834
Brejuro Avatar asked Nov 19 '15 19:11

Brejuro


1 Answers

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

like image 138
Bhairav Thakkar Avatar answered Sep 24 '22 21:09

Bhairav Thakkar