laggy android graphic view on huge data


I wanted to plot real time data via for data acquired in a Bluetooth thread.

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() {
                                    public void run() {

                        } catch (IOException e) {
                                    "BtConnectionThread run while loop: problem reading");

Activity code:

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

This works perfectly, but gets extremely laggy over time. The BT thread receives data with 100Hz - after the first few hundred data sets the memory usage is immense and the graph begins to lag. Is there a workaround or an alternative ringbuffer implementation?

Additional i wanted to disable the x-axis legend, but couln't find any command to archive this.

Regards, Lukas

First things first, you can hide the labels of the x-axis (provided that is what you want to do) by casting the following method :

your_graph.getGridLabelRenderer().setHorizontalLabelsVisible( false );

As for the laggyness part, I have experienced it too on graphs with a large set of points. The idea of a circular buffer seems to be a good one, if you do not need to visualize the whole history of your data. I would pair it with the

your_series.resetData( dataPoint[] my_data_points );

method to ensure a live update of the graph. Your addData function would append data to the circular buffer, which you would pass to the method above to update the graph on a timely basis.

I fear this can be quite resource-consuming if you want to refresh the graph at a high rate and with a large number of points, but you at least you would be able to control those two parameters.