I am using core plot to draw graphs. So far it seems to be a great framework but I have encountered some performance issues when I enable user interaction and perform a scroll.
At first I thought this was due to the number of points being plotted so I wrote a simple test app with very few points. Scrolling was still quite jerky despite the plot being as simple as possible. I get around 20-25 fps on an iPhone 4 with this plot.
Am I doing something wrong or is this just as fast as it gets with core plot?
My sample code is below:
- (void)viewDidLoad
{
[super viewDidLoad];
graph = [(CPTXYGraph *)[CPTXYGraph alloc] initWithFrame:CGRectZero];
CPTXYPlotSpace *plotSpace = (CPTXYPlotSpace *)graph.defaultPlotSpace;
plotSpace.xRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromDouble(0) length: CPTDecimalFromDouble(5)];
plotSpace.yRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromDouble(0) length:CPTDecimalFromDouble(5)];
plotSpace.allowsUserInteraction = YES;
plotSpace.globalYRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromDouble(-10) length:CPTDecimalFromDouble(100)];
plotSpace.globalXRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromInt(-10) length:CPTDecimalFromDouble(20)];
// Axes
CPTXYAxisSet *axisSet = (CPTXYAxisSet *)graph.axisSet;
CPTXYAxis *x = axisSet.xAxis;
x.majorIntervalLength = CPTDecimalFromInt(1);
x.orthogonalCoordinateDecimal = CPTDecimalFromInt(0);
x.axisConstraints = [CPTConstraints constraintWithLowerOffset:30];
CPTXYAxis *y = axisSet.yAxis;
y.majorIntervalLength = CPTDecimalFromInt(1);
y.minorTicksPerInterval = 0;
y.orthogonalCoordinateDecimal = CPTDecimalFromDouble(0);
y.axisConstraints = [CPTConstraints constraintWithLowerOffset:30];
// Create a plot that uses the data source method
CPTScatterPlot *dataSourceLinePlot = [[CPTScatterPlot alloc] init];
dataSourceLinePlot.identifier = @"1";
CPTMutableLineStyle *lineStyle = [dataSourceLinePlot.dataLineStyle mutableCopy];
lineStyle.lineWidth = 3.f;
lineStyle.lineColor = [CPTColor redColor];
dataSourceLinePlot.dataLineStyle = lineStyle;
dataSourceLinePlot.dataSource = self;
dataSourceLinePlot.delegate = self;
[graph addPlot:dataSourceLinePlot];
hostView.hostedGraph = graph;
}
-(NSUInteger)numberOfRecordsForPlot:(CPTPlot *)plot
{
return 20;
}
-(NSNumber *)numberForPlot:(CPTPlot *)plot field:(NSUInteger)fieldEnum recordIndex:(NSUInteger)index
{
return [NSNumber numberWithInt:index];
}