1

I want to develop an app which communicates with BLE sensors at 100 Hz and to plot real time data using GraphView. 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. I managed to receive data and to plot it but I have two concerns:

  • 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).
  • 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. 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

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

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.

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.

Thanks to take time to read this.

Regards, Arthur.

1 Answer 1

1

I was able to fix it by setting scrollToEnd to false in the appendData function... Was so easy.

Regards, Arthur.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.