简体   繁体   English

如何使用 GraphView 修复 x 轴的限制

[英]How to fix the limit of x axis with GraphView

I want to develop an app which communicates with BLE sensors at 100 Hz and to plot real time data using GraphView.我想开发一个应用程序,它以 100 Hz 的频率与 BLE 传感器进行通信,并使用 GraphView 与 plot 实时数据进行通信。 I want to plot data in an "ECG way of doing", by having always the same fixed x axis and the curve which plots during time and come back on the left of the graph if the plot has reached the right end of the graph.我想以“心电图方式”处理 plot 数据,方法是始终保持相同的固定 x 轴和随时间绘制的曲线,如果 plot 已到达图表的右端,则返回图表左侧。 I managed to receive data and to plot it but I have two concerns:我设法接收数据并发送到 plot 但我有两个担忧:

  • Sometimes, it became a bit laggy for like half a second, and I do not know if it comes from my app, or my phone (which is an OnePlus 6, having so quite great performances).有时,它会延迟半秒钟,我不知道它是来自我的应用程序,还是我的手机(这是一个 OnePlus 6,性能非常好)。
  • I am not able to "fix" the x axis limits... To try to explain it, the width of the x axis is fixed, but the curve starts plotting on the right part of the graph and fills the graph in the left direction until the curve has touched the left border of the graph.我无法“修复”x 轴限制...为了解释它,x 轴的宽度是固定的,但曲线开始绘制在图形的右侧并在左侧方向填充图形直到曲线触及图形的左边界。 However, this is not what I wanted to do.然而,这不是我想做的。

Here is some code snippets to help you understand what I have done wrong.以下是一些代码片段,可帮助您了解我做错了什么。

LineGraphSeries<DataPoint> series;
private int time = 0;
private int maxDataPoints = 200;

In OnCreate function在 OnCreate function

mDataGraph = (GraphView) findViewById(R.id.graph_data);
mDataGraph.getGridLabelRenderer().setHorizontalLabelsVisible(false);
mDataGraph.getGridLabelRenderer().setVerticalLabelsVisible(false);
mDataGraph.getGridLabelRenderer().setHighlightZeroLines(true);
mDataGraph.getGridLabelRenderer().setGridStyle(GridLabelRenderer.GridStyle.NONE);
mDataGraph.getViewport().setDrawBorder(true);
mDataGraph.setKeepScreenOn(true);

series = new LineGraphSeries<DataPoint>();
mDataGraph.addSeries(series);

// customize a little bit viewport
Viewport viewport = mDataGraph.getViewport();
viewport.setXAxisBoundsManual(true);
viewport.setMinX(0);
viewport.setMaxX(maxDataPoints);
viewport.setScalable(true);
viewport.setScrollable(true);

My function to handle data texts and plots我的 function 处理数据文本和绘图

private void displayData(String data) {
    if (data != null) {
        mDataField.setText(data);
        int dataNumber = Integer.parseInt(data);
        // Reset graph
        if (time == maxDataPoints){
            mDataGraph.removeAllSeries();
            series = new LineGraphSeries<DataPoint>();
            mDataGraph.addSeries(series);
            time = 0;
        }
        series.appendData(new DataPoint(time, dataNumber), true, maxDataPoints);
        time ++;
    }
}

Note that my template is the Bluetooth Le Gatt one.请注意,我的模板是蓝牙 Le Gatt 模板。

It is the first time I use this forum and I code in android studio (and even in java), so I hope that my explanations are clear and that someone can help me.这是我第一次使用这个论坛,我在 android 工作室(甚至在 java 中)编码,所以我希望我的解释清楚,有人可以帮助我。

Thanks to take time to read this.感谢您花时间阅读本文。

Regards, Arthur.问候,亚瑟。

I was able to fix it by setting scrollToEnd to false in the appendData function... Was so easy.我可以通过在 appendData function 中将 scrollToEnd 设置为 false 来修复它... 非常简单。

Regards, Arthur.问候,亚瑟。

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

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