我正在使用核心图绘制图表。到目前为止,它似乎是一个很棒的框架,但是当我启用用户交互并执行滚动时,我遇到了一些性能问题。
起初我认为这是由于绘制的点数,所以我编写了一个简单的测试应用程序,点数很少。尽管情节尽可能简单,但滚动仍然很生涩。有了这个情节,我在 iPhone 4 上获得了大约 20-25 fps。
我是在做错什么,还是与核心情节一样快?
我的示例代码如下:
- (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];
}