- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我正在使用 Scichart for android 编写一个实时绘图应用程序。我一直在用
FastLineRenderableSeries 作为我的数据系列的包装器
但我想知道为了最大限度地提高绘图速度,Android SciChart 还存在哪些其他技术?
特别是当我使用 IXyDataSeries 并将 x 轴大小从 10,000 点增加到 100,000 点时,我特别注意到性能下降。在我将大约 90,000 个点添加到我的 IXyDataSeries 之前,绘图的速度一直保持很快。
谢谢大家。我是 stackoverflow 的新手……与其说是 CS 人员,不如说是 mechE。
这是我的 graphFragment 类,它以字符串形式接收 UDP 传感器数据,将其拼接并将其添加到 IXyDataSeries。
public class GraphFragment extends Fragment {
//Various fields...
//UDP Settings
private UdpClient client;
private String hostname;
private int remotePort;
private int localPort;
//Use to communicate with UDPDataClass
private Handler handler;
private boolean listenerExists = false;
private int xBound = 100000; //**Graphing Slows if xBound is TOO large**
private int yBound = 5000;
private boolean applyBeenPressed = false;
private GraphDataSource dataSource; //Gets data from UDPDataClass
private SciChartSurface plotSurface; //Graphing Surface
protected final SciChartBuilder sciChartBuilder = SciChartBuilder.instance();
//Data Series containers
//Perhaps it would be better to use XyySeries here?
private final IXyDataSeries<Double, Double> dataSeriesSensor1 = sciChartBuilder.newXyDataSeries(Double.class, Double.class).build();
private final IXyDataSeries<Double, Double> dataSeriesSensor2 = sciChartBuilder.newXyDataSeries(Double.class, Double.class).build();
private final IXyDataSeries<Double, Double> dataSeriesSensor3 = sciChartBuilder.newXyDataSeries(Double.class, Double.class).build();
private final IXyDataSeries<Double, Double> dataSeriesSensor4 = sciChartBuilder.newXyDataSeries(Double.class, Double.class).build();
private final IXyDataSeries<Double, Double> dataSeriesSensor5 = sciChartBuilder.newXyDataSeries(Double.class, Double.class).build();
private final IXyDataSeries<Double, Double> dataSeriesSensor6 = sciChartBuilder.newXyDataSeries(Double.class, Double.class).build();
private ArrayList<IXyDataSeries<Double,Double>> dataSeriesList = new ArrayList<>(Arrays.asList(dataSeriesSensor1,dataSeriesSensor2,dataSeriesSensor3,dataSeriesSensor4, dataSeriesSensor5, dataSeriesSensor6));
private ArrayList<Double> xCounters = new ArrayList<>(Arrays.asList(0.0,0.0,0.0,0.0,0.0,0.0));
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
final View frag = inflater.inflate(R.layout.graph_fragment, container, false);
plotSurface = (SciChartSurface) frag.findViewById(R.id.dynamic_plot);
dataSource = new GraphDataSource(); //Run the data handling on a separate thread
dataSource.start();
UpdateSuspender.using(plotSurface, new Runnable() {
@Override
public void run() {
final NumericAxis xAxis = sciChartBuilder.newNumericAxis().withVisibleRange(0,xBound).build();
final NumericAxis yAxis = sciChartBuilder.newNumericAxis().withVisibleRange(0,yBound).build();
//These are wrappers for the series we will add the data to...It contains the formatting
final FastLineRenderableSeries rs1 = sciChartBuilder.newLineSeries().withDataSeries(dataSeriesSensor1).withStrokeStyle(ColorUtil.argb(0xFF, 0x40, 0x83, 0xB7)).build(); //Light Blue Color
final FastLineRenderableSeries rs2 = sciChartBuilder.newLineSeries().withDataSeries(dataSeriesSensor2).withStrokeStyle(ColorUtil.argb(0xFF, 0xFF, 0xA5, 0x00)).build(); //Light Pink Color
final FastLineRenderableSeries rs3 = sciChartBuilder.newLineSeries().withDataSeries(dataSeriesSensor3).withStrokeStyle(ColorUtil.argb(0xFF, 0xE1, 0x32, 0x19)).build(); //Orange Red Color
final FastLineRenderableSeries rs4 = sciChartBuilder.newLineSeries().withDataSeries(dataSeriesSensor4).withStrokeStyle(ColorUtil.argb(0xFF, 0xFF, 0xFF, 0xFF)).build(); //White color
final FastLineRenderableSeries rs5 = sciChartBuilder.newLineSeries().withDataSeries(dataSeriesSensor5).withStrokeStyle(ColorUtil.argb(0xFF, 0xFF, 0xFF, 0x99)).build(); //Light Yellow color
final FastLineRenderableSeries rs6 = sciChartBuilder.newLineSeries().withDataSeries(dataSeriesSensor6).withStrokeStyle(ColorUtil.argb(0xFF, 0xFF, 0x99, 0x33)).build(); //Light Orange color
Collections.addAll(plotSurface.getXAxes(), xAxis);
Collections.addAll(plotSurface.getYAxes(), yAxis);
Collections.addAll(plotSurface.getRenderableSeries(), rs1, rs2, rs3, rs4, rs5, rs6);
}
});
return frag;
}
//This class receives the UDP sensor data as messages to its handler
//Then it splices the data
//Adds the data to the IXySeries
//Then the UpdateSuspender updates the graph
//New data arrives approx every 50 ms (around 20x a second)
//Graphing slows when xAxis is increased to ~100,000
//X data is only counters...Only care about Y data
public class GraphDataSource extends Thread{
public void run(){
Looper.prepare();
//Get Data from UDP Data Class when its available
handler = new Handler(){
public void handleMessage(Message msg){
String sensorData = msg.getData().getString("data"); //Data receiveds
if(dataValid(sensorData)){
sensorData = sensorData.replaceAll("\\s", "");
final String[] dataSplit = sensorData.split(","); //split the data at the commas
UpdateSuspender.using(plotSurface, new Runnable() { //This updater graphs the values
@Override
public void run() {
spliceDataAndAddData(dataSplit);
}
});
}
}
};
Looper.loop();
}
/**
*
* @param data string of the udp data
* @return true if the data isn't corrupted..aka the correct length
*/
private boolean dataValid(String data){
return ((data.length() == 1350));
}
/**
*
* @param dataSplit String[] of the entire data
* Adds the each sensor data to the IXySeries representing the data
*/
private void spliceDataAndAddData(String[] dataSplit){
addToSensorSeries(dataSplit, 1);
addToSensorSeries(dataSplit, 2);
addToSensorSeries(dataSplit, 3);
addToSensorSeries(dataSplit, 4);
addToSensorSeries(dataSplit, 5);
addToSensorSeries(dataSplit, 6);
}
/**
*
* @param dataSplit data to split into individual sensor array
* must contain only string representations of numbers
* @param sensorSeriesNumber which sensors to collect the data points of
* Adds the data to the corresponding IXySeries
*/
private void addToSensorSeries(String[] dataSplit, int sensorSeriesNumber){
sensorSeriesNumber -= 1; //Adds each value individually to the series
double xcounter = xCounters.get(sensorSeriesNumber);
int i = sensorSeriesNumber;
int dataSize = dataSplit.length - 1;
String num = "";
while(true){
if(i < 6){ //This is the base case...add the first set of data
num = dataSplit[i];
try {
if(xcounter > xBound){
xcounter = 0;
dataSeriesList.get(sensorSeriesNumber).clear();
}
dataSeriesList.get(sensorSeriesNumber).append(xcounter, Double.parseDouble(num)); //appends every number...
}catch (Exception e){
//Corrupt data
}
}else if((i) <= dataSize && i >= 6){ //Will start to get hit after the second time
num = dataSplit[i];
try {
if(xcounter > xBound){
xcounter = 0;
dataSeriesList.get(sensorSeriesNumber).clear();
}
dataSeriesList.get(sensorSeriesNumber).append(xcounter, Double.parseDouble(num));
}catch (Exception e){
//Corrupt data
}
}else{
break;
}
xcounter++;
i += 6;
}
xCounters.set(sensorSeriesNumber,xcounter);
}
}
最佳答案
我查看了您的代码,但不确定我们是否可以对此做些什么。您的示例包含 6 个 XyDataSeries,XRange 从 0 到 100000,这在屏幕上给出了 600 000 个点,这对于 HTC One 上的实时示例来说非常好。在 SciChart 性能演示中,您可以看到仅使用 3 个 XyDataSeries 实例,这允许在每个系列中绘制更多点
披露:我是 SciChart Android 团队的首席开发人员
但我认为您可以通过在代码中添加一些优化来获得额外的 FPS。实时图表的主要问题在于更新图表的代码——它经常被调用,所以如果你在更新期间创建了一些对象并且不保存它,那么这可能会导致问题,因为 Android 中的 GC(GC 传递很慢而且它可以在 GC 收集所有未使用的对象时暂停所有应用程序的线程)。所以我建议你接下来做:
dataSeriesList.get(sensorSeriesNumber).append(xcounter, Double.parseDouble(num));
double xcounter = xCounters.get(sensorSeriesNumber);
xCounters.set(sensorSeriesNumber,xcounter);
我建议您使用 append override它接受 IValues。当您非常频繁地附加大量数据时,使用接受 IValue 的附加可以避免对基本类型进行不必要的装箱/拆箱。
希望对您有所帮助。
关于android - SciChart Android 实时绘图 : How to maximize graphing speed?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39810816/
我对这两个概念感到困惑:In-graph replication和 Between-graph replication阅读 Replicated training 时在 tensorflow 的官方
我对这两个概念感到困惑:In-graph replication和 Between-graph replication阅读 Replicated training 时在 tensorflow 的官方
我正在尝试使用 https://graph.windows.net/{teantId}/users/[email protected]/thumbnailPhoto?api-version=1.6 访
我正在尝试使用 Graphs.jl 模块从 Julia 中的图中获取子图。我有图,并将其顶点和边存储到列表中,然后我的算法在该列表中移动并删除不属于新子图的节点和边。到这一部分,一切正常,在整个算法之
我是 Arangodb 的新手。我对使用哪个图形 API 感到困惑。我可以在 http://localhost:8529/ url 看到一张图。官方视频讨论了 Gremlin(我也安装了它)。然后就是
截至今天,文档建议使用 Microsoft Graph 而不是 Azure AD Graph API 来访问 Azure AD/B2C 资源。 之前,通过 Azure AD Graph API,我们可
我们希望将 .NET 应用从使用 Azure AD Graph 迁移到 Microsoft Graph API。目前我们正在使用包 Microsoft.WindowsAzure.Configurati
也许我遗漏了什么,但我不知道为什么 GraphQL 的标题中有 graph。 我猜这与 Graph Theory 有关和 graph并且可以看到某种联系,但如果有人能用简单的术语解释它就太好了。 最佳
我正在尝试使用API使用户的Facebook Pages具有已关联的Instagram企业帐户: https://graph.facebook.com/v2.7/me/accounts?field
如何导出我通过调用 GraphPlot 获得的输出的调整大小版本 (或 TreePlot 如果它们产生不同的输出)到 jpg 文件? 目前,我只是调用 Export[file_name, G]在哪里
如何在使用 gremlin 查询创建边缘之前检查边缘是否已存在?如何更新现有边缘而不是删除并重新创建? 最佳答案 我不确定您是否还在寻找答案;然而,简单的答案是 Cosmos DB 在 Gremlin
我使用的是 Xcode 10.2.1 和 macOS Catalina Developer Beta 2。每当我尝试使用内存图调试器时,我都会收到此错误: Memory Graph Debugger:
我正在设置一个机器人以在Facebook页面上自动发布。但是,当我运行脚本时,图形API会引发以下错误: Graph returned an error: (#200) Requires either
如何制定包含非英语字符(例如日耳曼语Umlauts)的Microsoft Graph /myOrganization/users OData查询? 例子: 我的租户中有一个名为“ThomasMülle
我正在寻找发布目标帖子时可以与Facebook Graph API一起使用的国家/州/城市列表。 我在this页面上找到了一个JSON文件,但是该文件无法正确解析,我也怀疑它是否可以用于发布目标,因为
关于 Graph API,帖子的分享数、帖子见解的分享数和页面上显示的分享数不相同。我假设这些代表相同的计数。我的假设错了吗? 来自帖子: https://graph.facebook.com/XXX
我正在尝试访问作为嵌套子站点一部分的列表的项目,如下所示: https://{mytenant}.sharepoint.com/ vendorSiteCollection/ v
我打算开发一个应用程序,但开发人员告诉我每个 IP 每 600 秒有 600 次调用的限制。该应用程序有很多场景,这还不够。有没有办法以某种方式增加限制?或者 Facebook 是否提供任何高级帐户或
我在 Neo4j 中创建了一张伦敦地铁 map 。站点通过 :CONNECTED_TO 关系连接,时间值表示停止之间需要多长时间(目前这些是我为测试输入的随机值)。位于多条线路上的车站每条线路都有一个
我正在尝试拉回所有用户的列表,我的预期结果将是大约 20,000 个用户。 图表似乎将我限制为 1000。 图调用https://graph.microsoft.com/v1.0/users返回 10
我是一名优秀的程序员,十分优秀!