简体   繁体   English

iOS CorePlot令人难以置信的缓慢初始化

[英]iOS CorePlot incredibly slow initialization

I'm trying to use CorePlot for plotting data collected by sensors on iPhone and I almost finished it, but initialization of Coreplot is very very slow. 我正在尝试使用CorePlot绘制由iPhone上的传感器收集的数据,而我几乎完成了,但是Coreplot初始化非常慢。 Here is my code in viewDidLoad method: 这是我在viewDidLoad方法中的代码:

    CPTGraphHostingView* hostView = [[CPTGraphHostingView alloc] initWithFrame:self.coreplot.frame];
    [self.view addSubview: hostView];

    // Create a CPTGraph object and add to hostView
    graph = [[CPTXYGraph alloc] initWithFrame:hostView.bounds];
    hostView.hostedGraph = graph;

    // Get the (default) plotspace from the graph so we can set its x/y ranges
    CPTXYPlotSpace *plotSpace = (CPTXYPlotSpace *) graph.defaultPlotSpace;

    // Note that these CPTPlotRange are defined by START and LENGTH (not START and END) !!
    [plotSpace setYRange: [CPTPlotRange plotRangeWithLocation:CPTDecimalFromFloat( -2000 ) length:CPTDecimalFromFloat( 4000 )]];
    [plotSpace setXRange: [CPTPlotRange plotRangeWithLocation:CPTDecimalFromFloat( 0 ) length:CPTDecimalFromFloat( 100)]];
    // Create the plot (we do not define actual x/y values yet, these will be supplied by the datasource...)
    CPTScatterPlot* plot = [[CPTScatterPlot alloc] initWithFrame:CGRectZero];

    // Let's keep it simple and let this class act as datasource (therefore we implemtn <CPTPlotDataSource>)
    plot.dataSource = self;
    CPTMutableLineStyle *lineStyle = [CPTMutableLineStyle lineStyle];
    lineStyle.lineWidth = 2.0f;
    lineStyle.lineColor = [CPTColor redColor];
    plot.dataLineStyle = lineStyle;
    // Finally, add the created plot to the default plot space of the CPTGraph object we created before
    [graph addPlot:plot toPlotSpace:graph.defaultPlotSpace];
    [graph.defaultPlotSpace scaleToFitPlots:[graph allPlots]];

It takes forever to start the application, but when it finishes loading, it works well. 启动应用程序需要花费很多时间,但是完成加载后,它可以很好地工作。 Is there any faster way of loading because this is unacceptable for me at the moment. 是否有任何更快的加载方式,因为目前我不可接受。

Update the axis labeling policy and/or the related properties to reduce the number of tick marks and axis labels. 更新轴标签策略和/或相关属性以减少刻度线和轴标签的数量。 The defaults create ticks and labels one unit apart along each axis—with the ranges shown in your code snippet, that's over 6,000 labels to create and display. 默认值会创建刻度线,并沿每个轴间隔一个单位的标签-代码段中显示的范围,可以创建和显示的标签超过6,000个。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM