I am following the tutorial here about core plot here.... http://www.switchonthecode.com/tutorials/using-core-plot-in-an-iphone-application
I am getting errors with the following lines of code
//SAYING INCOMPATIBLE TYPE FOR AURGUMENT 1 'setMajorIntervalLength'
axisSet.xAxis.majorIntervalLength = [NSDecimalNumber decimalNumberWithString:@"5"];
// request for member 'axisLabelOffset' in something not a structure or union
axisSet.xAxis.axisLabelOffset = 3.0f;
//request for member 'bounds' in something not a structure or union
CPScatterPlot *xSquaredPlot = [[[CPScatterPlot alloc] initWithFrame:graph.defaultPlotSpace.bounds] autorelease];
Here is my code now I am not getting any compiler errors anymore but its crashing and not loading the view please take a look if you can
@implementation FirstCorePlotViewController
(void)viewDidLoad { [super viewDidLoad];
graph = [[CPXYGraph alloc] initWithFrame: self.view.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)];
CPXYAxisSet *axisSet = (CPXYAxisSet *)graph.axisSet;
CPLineStyle *lineStyle = [CPLineStyle lineStyle]; lineStyle.lineColor = [CPColor blackColor]; lineStyle.lineWidth = 2.0f;
axisSet.xAxis.majorIntervalLength =CPDecimalFromString(@"5"); 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 = CPDecimalFromString(@"5"); 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 *)[CPScatterPlot alloc] initWithFrame: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.defaultPlotSymbol = greenCirclePlotSymbol;
CPScatterPlot *xInversePlot = [[(CPScatterPlot *)[CPScatterPlot alloc] initWithFrame:graph.bounds] autorelease];
xInversePlot.identifier = @"X Inverse Plot"; xInversePlot.dataLineStyle.lineWidth = 1.0f; xInversePlot.dataLineStyle.lineColor = [CPColor blueColor]; xInversePlot.dataSource = self; [graph addPlot:xInversePlot]; }
-(NSUInteger)numberOfRecords { return 51; }
-(NSNumber *)numberForPlot:(CPPlot *)plot field:(NSUInteger)fieldEnum
recordIndex:(NSUInteger)index
{
double val = (index/5.0)-5;
if(fieldEnum == CPScatterPlotFieldX)
{ return [NSNumber numberWithDouble:val]; }
else
{
if(plot.identifier == @"X Squared Plot")
{ return [NSNumber numberWithDouble:val*val]; }
else
{ return [NSNumber numberWithDouble:1/val]; }
}
}
@end