简体   繁体   English

Android GraphView:setMinX(0)无法正常工作并产生负x轴值

[英]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. 我一直试图在我的Android项目中使用GraphView库来基于x轴绘制时间绘制一些点。 To do this, I wanted to constrain my x axis form 0 to 60 (representing seconds). 为此,我想将我的x轴约束为0到60(代表秒)。 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 但是当我输入例如x值为0和1的前两个数据点时

    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 绘图的x轴突然移动,以至于最右边的x点是1,而左边的一切都是负的(我在图中用方框将其装箱了): 负的X轴图像

Is there any way to freeze the x axis so that it is only positive? 有什么方法可以冻结x轴,使其仅是正数? 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. 我只需要将参数从true更改为false。 This value according to the GraphView docs is (Boolean ScrolltoEnd) so setting it false will eliminate the shift of the x axis. 根据GraphView docs,此值是(Boolean ScrolltoEnd),因此将其设置为false将消除x轴的偏移。 So it should look like this: 所以它应该看起来像这样:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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