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.
numberOfRecordsForPlotreturn?). How are your data points stored and accessed innumberForPlot? Maybe show your numberForPlot method too. - Jeff Loughlin