iOS CorePlot初始化速度极慢

时间:2014-05-12 15:23:52

标签: ios objective-c core-plot

我试图使用CorePlot来绘制iPhone上的传感器收集的数据,而我几乎完成了它,但Coreplot的初始化非常慢。这是我在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]];

启动应用程序需要永远,但是当它完成加载时,它运行良好。有没有更快的加载方式,因为这对我来说是不可接受的。

1 个答案:

答案 0 :(得分:2)

更新轴标签政策和/或相关属性,以减少刻度线和轴标签的数量。默认值创建刻度线并沿每个轴标记一个单位 - 使用代码段中显示的范围,即可创建和显示超过6,000个标签。