简体   繁体   中英

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. Here is my code in viewDidLoad method:

    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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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