1
votes

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.

1
Define "takes forever"...how many points in your data source (what does numberOfRecordsForPlot return?). How are your data points stored and accessed in numberForPlot? Maybe show your numberForPlot method too. - Jeff Loughlin
"takes forever" is like 7-10 seconds on iPhone 5 when starting app (without any points because I'm collecting points during the runtime). Here is numberForPlot method: if(fieldEnum == CPTScatterPlotFieldX) return [NSNumber numberWithInt: index]; else return [self.points objectAtIndex:index]; - user1775746

1 Answers

2
votes

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.