Android GraphView:setMinX(0) 不工作并产生负 x 轴值
Android GraphView: setMinX(0) not working and produces negative x axis values
我一直在尝试在我的 Android 项目中使用 GraphView 库,以基于时间的 x 轴绘制几个点。为此,我想将我的 x 轴形式限制在 0 到 60(代表秒)之间。我使用以下代码完成了此操作:
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);
但是当我输入前两个 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);
绘图的x轴突然移动,最右边的x点是1,左边的都是负数(我在图中已经把它框起来了):
Negative X axis image
有什么方法可以冻结x轴,让它只为正数吗?
谢谢
我在调用
时发现了我的问题
series.appendData(new DataPoint(0,70), true, 100);
我只需要将参数从 true 更改为 false。根据 GraphView 文档,此值为 (Boolean ScrolltoEnd),因此将其设置为 false 将消除 x 轴的移动。所以它应该是这样的:
series.appendData(new DataPoint(0,70), false, 100);
我一直在尝试在我的 Android 项目中使用 GraphView 库,以基于时间的 x 轴绘制几个点。为此,我想将我的 x 轴形式限制在 0 到 60(代表秒)之间。我使用以下代码完成了此操作:
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);
但是当我输入前两个 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);
绘图的x轴突然移动,最右边的x点是1,左边的都是负数(我在图中已经把它框起来了): Negative X axis image
有什么方法可以冻结x轴,让它只为正数吗? 谢谢
我在调用
时发现了我的问题series.appendData(new DataPoint(0,70), true, 100);
我只需要将参数从 true 更改为 false。根据 GraphView 文档,此值为 (Boolean ScrolltoEnd),因此将其设置为 false 将消除 x 轴的移动。所以它应该是这样的:
series.appendData(new DataPoint(0,70), false, 100);