Reputation: 21
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:
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.
Upvotes: 1
Views: 385
Reputation: 21
I was able to fix it by setting scrollToEnd to false in the appendData function... Was so easy.
Regards, Arthur.
Upvotes: 1