View graph in android

I would like to build real-time data through http://www.android-graphview.org/ for the data received in the Bluetooth stream.

Thread Code:

InputStream tmpIn = mSocket.getInputStream(); while (true) { try { BufferedReader r = new BufferedReader(new InputStreamReader(tmpIn)); String line; while ((line = r.readLine()) != null) { final String tmp = line; runOnUiThread(new Runnable() { @Override public void run() { addData(Integer.parseInt(tmp)); } }); } } catch (IOException e) { Log.e("BT", "BtConnectionThread run while loop: problem reading"); e.printStackTrace(); break; } } } 

Operation code:

 public void addData(int data){ series.appendData(new DataPoint(lastx,data),true,winSize); lastx++; } 

This works fine, but lags far behind over time. The BT stream receives data at a frequency of 100 Hz - after the first few hundred data sets exchange memory, and the graph begins to lag. Is there a workaround or alternative ringbuffer implementation?

Additionally, I wanted to disable the X-axis legend, but did not find any command to archive it.

Regards, Lukas

0
source share
2 answers

First of all, you can hide the x-axis labels (provided that you want to do this) by doing the following method:

 your_graph.getGridLabelRenderer().setHorizontalLabelsVisible( false ); 

As for the delay part, I also experienced this on charts with a large set of points. The idea of ​​a circular buffer seems good if you don't need to visualize the entire history of your data. I would associate it with

 your_series.resetData( dataPoint[] my_data_points ); 

to provide live schedule updates. The addData function will add data to the circular buffer, which you will pass to the method above to update the chart in a timely manner.

I am afraid that this can be quite resource-intensive if you want to update the chart at a high speed and with a lot of points, but at least you can control these two parameters.

0
source

you can reuse datapoint objects. The problem is that you are creating new objects, and when the heap is full, jvm should gc it.

try reusing objects somehow.

0
source

All Articles