在庞大的数据laggy Android的图形视图 [英] android graph view laggy on huge data
问题描述
我想通过 http://www.android-graphview.org/对蓝牙线程获取的数据。
I wanted to plot real time data via http://www.android-graphview.org/ for data acquired in a Bluetooth 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;
}
}
}
活动code:
public void addData(int data){
series.appendData(new DataPoint(lastx,data),true,winSize);
lastx++;
}
这完美的作品,但随着时间的推移变得非常laggy。
该BT线程接收的数据为100Hz - 前几百个数据集之后的内存使用量是巨大的和图形开始滞后。是否有解决方法或替代ringbuffer实现?
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?
另外我想禁用x轴的传说,但couln't发现任何命令来归档此。
Additional i wanted to disable the x-axis legend, but couln't find any command to archive this.
问候,
卢卡斯
Regards, Lukas
推荐答案
首先第一件事情,你可以隐藏x轴的标签(前提是你想要做什么)通过铸造下面的方法:
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 );
对于laggyness的一部分,我已经经历过它与一个大点的集合图。循环缓冲区的想法似乎是一个很好的,如果你不需要显示数据的整个历史。我将与配对
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 );
方法,以确保该图的现场更新。您的 addData em>的功能将数据追加到循环缓冲区,这将传递给上面的方法来及时更新的图形。
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.
这篇关于在庞大的数据laggy Android的图形视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!