简体   繁体   中英

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM