redlime9
redlime9

Reputation: 53

Android GraphView: setMinX(0) not working and produces negative x axis values

I have been trying to use the GraphView library in my Android project to plot a few points based on the x axis being time. To do this, I wanted to constrain my x axis form 0 to 60 (representing seconds). I did this using the following code:

    graph = (GraphView) findViewById(R.id.graph);

    grapRend= graph.getGridLabelRenderer();


    graph.getViewport().setScrollable(true);
    graph.getViewport().setXAxisBoundsManual(true);
    graph.getViewport().setMinX(0);
    graph.getViewport().setMaxX(60);

But when I input my first two datapoints with x values of 0 and 1 for example

    series = new LineGraphSeries<DataPoint>(new DataPoint[] {});
    series.appendData(new DataPoint(0,70), true, 100);
    series.appendData(new DataPoint(1,73), true, 100);

The x axis of the plot suddenly shifts so that the rightmost x point is 1 and everything to the left is negative (I have boxed it in the picture ): Negative X axis image

Is there any way to freeze the x axis so that it is only positive? Thanks

Upvotes: 1

Views: 1372

Answers (1)

redlime9
redlime9

Reputation: 53

I found my problem, when calling

series.appendData(new DataPoint(0,70), true, 100);

I simply need to change the argument from true to false. This value according to the GraphView docs is (Boolean ScrolltoEnd) so setting it false will eliminate the shift of the x axis. So it should look like this:

series.appendData(new DataPoint(0,70), false, 100);

Upvotes: 2

Related Questions