Coreplot on iPhone
I followed Using Core Plot in an iPhone Application to generate a graph. I got some errors though. I originally wanted to comment on the tutorial page but wasn’t allowed to. The errors,
/Users/tilaye/Desktop/apps/CorePlotTest/Classes/CorePlotTestViewController.m:106: error: incompatible type for argument 1 of 'setMajorIntervalLength:' /Users/tilaye/Desktop/apps/CorePlotTest/Classes/CorePlotTestViewController.m:113: error: request for member 'axisLabelOffset' in something not a structure or union /Users/tilaye/Desktop/apps/CorePlotTest/Classes/CorePlotTestViewController.m:115: error: incompatible type for argument 1 of 'setMajorIntervalLength:' /Users/tilaye/Desktop/apps/CorePlotTest/Classes/CorePlotTestViewController.m:122: error: request for member 'axisLabelOffset' in something not a structure or union /Users/tilaye/Desktop/apps/CorePlotTest/Classes/CorePlotTestViewController.m:125: error: request for member 'bounds' in something not a structure or union /Users/tilaye/Desktop/apps/CorePlotTest/Classes/CorePlotTestViewController.m:135: error: request for member 'defaultPlotSymbol' in something not a structure or union /Users/tilaye/Desktop/apps/CorePlotTest/Classes/CorePlotTestViewController.m:138: error: request for member 'bounds' in something not a structure or union replaced axisLabelOffset with labelOffset,
I did the following to work around the issue,
replaced axisLabelOffset with labelOffset
replaced graph.defaultPlotSpace.bounds with graph.defaultPlotSpace.graph.bounds
replaced [NSDecimalNumber decimalNumberWithString:@"5"] with [[NSDecimalNumber decimalNumberWithString:@"5"] decimalValue]
My final working viewDidLoad method was then,
- (void)viewDidLoad {
[super viewDidLoad];
graph = [[CPXYGraph alloc] initWithFrame: self.view.bounds];
self.view = [[CPLayerHostingView alloc]initWithFrame:[UIScreen mainScreen].bounds];
CPLayerHostingView *hostingView = (CPLayerHostingView *)self.view;
hostingView.hostedLayer = graph;
graph.paddingLeft = 20.0;
graph.paddingTop = 20.0;
graph.paddingRight = 20.0;
graph.paddingBottom = 20.0;
CPXYPlotSpace *plotSpace = (CPXYPlotSpace *)graph.defaultPlotSpace;
plotSpace.xRange = [CPPlotRange plotRangeWithLocation:CPDecimalFromFloat(-6)
length:CPDecimalFromFloat(12)];
plotSpace.yRange = [CPPlotRange plotRangeWithLocation:CPDecimalFromFloat(-5)
length:CPDecimalFromFloat(30)];
CPLineStyle *lineStyle = [CPLineStyle lineStyle];
lineStyle.lineColor = [CPColor blackColor];
lineStyle.lineWidth = 2.0f;
CPXYAxisSet *axisSet = (CPXYAxisSet *)graph.axisSet;
axisSet.xAxis.majorIntervalLength = [[NSDecimalNumber decimalNumberWithString:@"5"] decimalValue];
axisSet.xAxis.minorTicksPerInterval = 4;
axisSet.xAxis.majorTickLineStyle = lineStyle;
axisSet.xAxis.minorTickLineStyle = lineStyle;
axisSet.xAxis.axisLineStyle = lineStyle;
axisSet.xAxis.minorTickLength = 5.0f;
axisSet.xAxis.majorTickLength = 7.0f;
axisSet.xAxis.labelOffset = 3.0f;
axisSet.yAxis.majorIntervalLength = [[NSDecimalNumber decimalNumberWithString:@"5"] decimalValue];
axisSet.yAxis.minorTicksPerInterval = 4;
axisSet.yAxis.majorTickLineStyle = lineStyle;
axisSet.yAxis.minorTickLineStyle = lineStyle;
axisSet.yAxis.axisLineStyle = lineStyle;
axisSet.yAxis.minorTickLength = 5.0f;
axisSet.yAxis.majorTickLength = 7.0f;
axisSet.yAxis.labelOffset = 3.0f;
CPScatterPlot *xSquaredPlot = [[[CPScatterPlot alloc]
initWithFrame:graph.defaultPlotSpace.graph.bounds] autorelease];
xSquaredPlot.identifier = @"X Squared Plot";
xSquaredPlot.dataLineStyle.lineWidth = 1.0f;
xSquaredPlot.dataLineStyle.lineColor = [CPColor redColor];
xSquaredPlot.dataSource = self;
[graph addPlot:xSquaredPlot];
CPPlotSymbol *greenCirclePlotSymbol = [CPPlotSymbol ellipsePlotSymbol];
greenCirclePlotSymbol.fill = [CPFill fillWithColor:[CPColor greenColor]];
greenCirclePlotSymbol.size = CGSizeMake(2.0, 2.0);
[xSquaredPlot setPlotSymbol:greenCirclePlotSymbol];
CPScatterPlot *xInversePlot = [[[CPScatterPlot alloc]
initWithFrame:graph.defaultPlotSpace.graph.bounds] autorelease];
xInversePlot.identifier = @"X Inverse Plot";
xInversePlot.dataLineStyle.lineWidth = 1.0f;
xInversePlot.dataLineStyle.lineColor = [CPColor blueColor];
xInversePlot.dataSource = self;
[graph addPlot:xInversePlot];
}
I also got
/Users/tilaye/Desktop/apps/TestApp/Classes/TaggedVideoGraphViewController.m:135: warning: method definition for '-numberOfRecordsForPlot:' not found
and changed my function signature from
-(NSUInteger)numberOfRecords {
to
-(NSUInteger)numberOfRecordsForPlot:(CPPlot *)plot {
Posted in: Objective C, iPhone
5 Comments
Comments RSS
TrackBack Identifier URI
Leave a comment

