Core Plot CPTScatterPlot 'Line Graph' not showing - iphone

So my problem is simple. I am trying to switch my chart from a bar graph to a line graph but my line chart does not show/plot. I use similar code for my CPTBarPlot 'Bar Chart' and this plots/shows correctly.
My Bar Plot Code which plots correctly is:
CPTBarPlot *barPlot = nil;
barPlot = [CPTBarPlot tubularBarPlotWithColor:[CPTColor colorWithComponentRed:0.9294f green:0.3960f blue:0.5921f alpha:1.0f] horizontalBars:NO];
barPlot.fill = [CPTFill fillWithColor:[CPTColor colorWithComponentRed:0.9294f green:0.3960f blue:0.5921f alpha:1.0f]];
barPlot.opacity = 0.8f;
barPlot.dataSource = self;
barPlot.delegate = self;
barPlot.baseValue = CPTDecimalFromString(#"0");
barPlot.barOffset = CPTDecimalFromFloat(0.50f);
switch (graphType) {
case kWeightThreeMonth:
{
barPlot.identifier = [GraphsViewController threeMonthBarPlotIdentifier];
}
break;
case kWeightSixMonth:
{
barPlot.identifier = [GraphsViewController sixMonthBarPlotIdentifier];
}
break;
case kWeightNineMonth:
{
barPlot.identifier = [GraphsViewController nineMonthBarPlotIdentifier];
}
break;
default:
break;
}
barPlot.barCornerRadius = 2.0f;
barPlot.lineStyle = nil;
[lineGraph addPlot:barPlot toPlotSpace:plotSpace];
My Line Plot Code which does not show is:
// Create a blue plot area
CPTScatterPlot *boundLinePlot = [[[CPTScatterPlot alloc] init] autorelease];
CPTMutableLineStyle *lineStyle = [CPTMutableLineStyle lineStyle];
lineStyle.miterLimit = 1.0f;
lineStyle.lineWidth = 3.0f;
lineStyle.lineColor = [CPTColor redColor];
boundLinePlot.dataLineStyle = lineStyle;
switch (graphType) {
case kWeightThreeMonth:
{
boundLinePlot.identifier = [GraphsViewController threeMonthBarPlotIdentifier];
}
break;
case kWeightSixMonth:
{
boundLinePlot.identifier = [GraphsViewController sixMonthBarPlotIdentifier];
}
break;
case kWeightNineMonth:
{
boundLinePlot.identifier = [GraphsViewController nineMonthBarPlotIdentifier];
}
break;
default:
break;
}
boundLinePlot.dataSource = self;
boundLinePlot.delegate = self;
[lineGraph addPlot:boundLinePlot toPlotSpace:plotSpace];
// Do a blue gradient
CPTColor *areaColor1 = [CPTColor colorWithComponentRed:0.3 green:0.3 blue:1.0 alpha:0.8];
CPTGradient *areaGradient1 = [CPTGradient gradientWithBeginningColor:areaColor1 endingColor:[CPTColor clearColor]];
areaGradient1.angle = -90.0f;
CPTFill *areaGradientFill = [CPTFill fillWithGradient:areaGradient1];
boundLinePlot.areaFill = areaGradientFill;
boundLinePlot.areaBaseValue = [[NSDecimalNumber zero] decimalValue];
// Add plot symbols
CPTMutableLineStyle *symbolLineStyle = [CPTMutableLineStyle lineStyle];
symbolLineStyle.lineColor = [CPTColor blackColor];
CPTPlotSymbol *plotSymbol = [CPTPlotSymbol ellipsePlotSymbol];
plotSymbol.fill = [CPTFill fillWithColor:[CPTColor blueColor]];
plotSymbol.lineStyle = symbolLineStyle;
plotSymbol.size = CGSizeMake(10.0, 10.0);
boundLinePlot.plotSymbol = plotSymbol;
Am I missing something here? I would of thought that the datasource etc would all work the same way considering the Bar Plot works correctly. I am simply just trying to switch from a bar chart, to a line chart.
Any help would be much appreciated.
Kind regards,
Dan

You may need to reload your plot's data. Try doing this:
[lineGraph reloadData]

This was actually my own fault.
In the dataSource methods;
-(NSUInteger)numberOfRecordsForPlot:(CPTPlot *)plot
-(NSNumber *)numberForPlot:(CPTPlot *)plot field:(NSUInteger)fieldEnum recordIndex:(NSUInteger)index
I was doing an If statement of;
if ( [plot isKindOfClass:[CPTBarPlot class]] ){
Ofcourse I was using a CPTScatterPlot so my code was not being called. Doh.

Related

How to set only one major line in core plot?

hi i am creating a graph using core plot, i want to change line style for major and minor line ,line style is changed but we have two major line top and bottom line in core plot how to remove top major line
- (void) setupGraphAxis: (CPTXYGraph *) graph {
CPTColor *axisColor = [CPTColor colorWithComponentRed:255.0/255.0 green:255.0/255.0 blue:255.0/255.0 alpha:0.75];
CPTMutableLineStyle *axisLineStyle = [CPTMutableLineStyle lineStyle];
axisLineStyle.lineWidth = 1.5f;
axisLineStyle.lineColor = axisColor;
CPTMutableLineStyle *dashLineStyle = [CPTMutableLineStyle lineStyle];
dashLineStyle.lineColor = axisColor;
dashLineStyle.lineWidth = 1.5f;
dashLineStyle.dashPattern = [NSArray arrayWithObjects:[NSDecimalNumber numberWithInt:1],[NSDecimalNumber numberWithInt:2],nil];
dashLineStyle.patternPhase = 0.0f;
CPTMutableLineStyle *fullLineStyle = [CPTMutableLineStyle lineStyle];
fullLineStyle.lineColor = axisColor;
fullLineStyle.lineWidth = 1.5f;
//fullLineStyle.dashPattern = [NSArray arrayWithObjects:[NSDecimalNumber numberWithInt:1],nil];
fullLineStyle.lineCap = 0;
fullLineStyle.patternPhase = 0.0f;
//Configure x-axis
CPTXYAxisSet *axisSet = (CPTXYAxisSet *) graph.axisSet;
CPTXYAxis *x = axisSet.xAxis;
x.axisLineStyle = nil;
x.orthogonalCoordinateDecimal = CPTDecimalFromString(#"0");
x.minorTickLineStyle = nil;
x.majorTickLineStyle = nil;
CPTAxisLabelingPolicy policy = CPTAxisLabelingPolicyAutomatic;
x.labelingPolicy = policy;
x.labelTextStyle = nil;
x.preferredNumberOfMajorTicks = 1;
CPTXYAxis *y = axisSet.yAxis;
y.axisLineStyle = nil;
y.orthogonalCoordinateDecimal = CPTDecimalFromString(#"0");
y.minorTickLineStyle = nil;
y.majorTickLineStyle = nil;
y.majorGridLineStyle = fullLineStyle;
y.minorGridLineStyle = dashLineStyle;
y.labelingPolicy = policy;
y.preferredNumberOfMajorTicks = 1;
}
You can use the labelExclusionRanges property of the axis to tell it to skip over certain values when creating ticks, grid lines, and labels. If you still want ticks and/or labels at that point, you might need to add another invisible y-axis that only draws the grid lines and let the original y-axis draw everything else.

How to dynamically change Core Plot‘s label

I encountered a problem when using a custom label in Core Plot:
My Core Plot supports zoom.
The x-axis label is custom x.axisLabels
On first load, the interface is normal, but when I narrow Core Plot, the axis labels overlap together.
How to design a level on the label? For example, when the minimum level only shows a year, in level display date, the maximum level shows the date.
- (void)initPlotGraph
{
graph = [[CPTXYGraph alloc] initWithFrame:CGRectZero];
self.hostedGraph = graph;
locationLabels = [[NSMutableArray alloc]init];
graph.plotAreaFrame.paddingLeft += 5.0;
graph.plotAreaFrame.paddingTop += 5.0;
graph.plotAreaFrame.paddingRight += 5.0;
graph.plotAreaFrame.paddingBottom += 17.5;
//[self setAllowPinchScaling:NO];
// Setup scatter plot space
plotSpace = (CPTXYPlotSpace *)graph.defaultPlotSpace;
plotSpace.allowsUserInteraction = YES;
plotSpace.delegate = self;
plotSpace.yRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromInt(0)length:CPTDecimalFromFloat(1+0.3)];
plotSpace.globalYRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromInt(0)length:CPTDecimalFromFloat(1+0.3)];
[self initPlotAxis];
}
- (void)initPlotAxis
{
CPTMutableLineStyle *axisLineStyle = [CPTMutableLineStyle lineStyle];
axisLineStyle.lineWidth = 2;
axisLineStyle.lineColor = [CPTColor colorWithComponentRed:CPTFloat(0.11765) green:CPTFloat(0.49804) blue:CPTFloat(0.87451) alpha:CPTFloat(1)];
CPTMutableLineStyle *axisTickLineStyle = [CPTMutableLineStyle lineStyle];
axisTickLineStyle.lineWidth = 0;
CPTLineCap *lineCap = [CPTLineCap sweptArrowPlotLineCap];
lineCap.size = CGSizeMake(10, 10);
lineCap.lineCapType = CPTLineCapTypeNone;
// Axes
// Label x axis with a fixed interval policy
lineCap.lineStyle = axisLineStyle;
lineCap.fill = [CPTFill fillWithColor:[CPTColor colorWithComponentRed:CPTFloat(0.29019) green:CPTFloat(0.54118) blue:CPTFloat(0.76471) alpha:CPTFloat(1)]];
CPTXYAxisSet *axisSet = (CPTXYAxisSet *)graph.axisSet;
CPTXYAxis *x = axisSet.xAxis;
x.majorIntervalLength = CPTDecimalFromInt(1);
x.axisLineStyle = axisLineStyle;
x.axisConstraints = [CPTConstraints constraintWithRelativeOffset:0];
x.axisLineCapMax = lineCap;
x.axisLabels = [self buildLabelTitle];
x.labelingPolicy = CPTAxisLabelingPolicyNone;
x.minorTickLocations = [NSSet setWithArray:locationLabels];
// Label y with an automatic label policy.
lineCap.lineStyle = axisLineStyle;
lineCap.fill = [CPTFill fillWithColor:[CPTColor colorWithComponentRed:CPTFloat(0.29019) green:CPTFloat(0.54118) blue:CPTFloat(0.76471) alpha:CPTFloat(1)]];
CPTXYAxis *y = axisSet.yAxis;
// y.majorIntervalLength = CPTDecimalFromDouble(5);
y.majorTickLineStyle = axisTickLineStyle;
y.minorTickLineStyle = axisTickLineStyle;
y.axisLineStyle = axisLineStyle;
y.axisLineCapMax = lineCap;
y.axisConstraints = [CPTConstraints constraintWithRelativeOffset:0];
// Set axes
graph.axisSet.axes = [NSArray arrayWithObjects:x, y, nil];
}
- (NSMutableSet*)buildLabelTitle
{
NSMutableSet *newAxisLabels = [NSMutableSet set];
CPTMutableTextStyle *textStyleB = [CPTMutableTextStyle textStyle];
textStyleB.color = [CPTColor colorWithComponentRed:CPTFloat((float)0x09/0xFF) green:CPTFloat((float)0x31/0xFF) blue:CPTFloat((float)0x4A/0xFF) alpha:CPTFloat(1)];
plotSpace.xRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromInt(corePlotNums - 9)length:CPTDecimalFromInt(10)];
plotSpace.globalXRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromInt(0) length:CPTDecimalFromInt(corePlotNums + 1)];
for ( NSUInteger i = 1; i < corePlotNums + 1; i++)
{
CPTAxisLabel *newLabel = [[CPTAxisLabel alloc] initWithText:[[m_labelStr objectAtIndex:i-1] substringWithRange:NSMakeRange(5, 11)] textStyle:textStyleB];
newLabel.tickLocation = CPTDecimalFromUnsignedInteger(i);
newLabel.offset = 5;
[newAxisLabels addObject:newLabel];
[newLabel release];
}
return newAxisLabels;
}
If the user is allowed to change the plot ranges (i.e., by pinch zooming), use a plot space delegate to monitor changes to the plot space. Use the new plot ranges and the size of the plot area to determine what time scale to use and how many labels to display. Adjust the axis labeling properties as needed.

Core plot : ios show two y axis and ScaterPlot and Bar Plot in Same CPTGraph

Hi please guide me write way to show two Y axis (left side and right side) with one x axis using core plot , and also i have to draw Scaterplot and barplot both in single CPTGraph.
CPTScatter plot show on right side Y axis with -ve direction .
My Code snippet
-(void)configureAxes
{
// 1 - Configure styles
CPTMutableTextStyle *axisTitleStyle = [CPTMutableTextStyle textStyle];
axisTitleStyle.color = [CPTColor whiteColor];
axisTitleStyle.fontName = #"Helvetica-Bold";
axisTitleStyle.fontSize = 8.0f;
CPTMutableLineStyle *axisLineStyle = [CPTMutableLineStyle lineStyle];
axisLineStyle.lineWidth = 2.0f;
axisLineStyle.lineColor = [[CPTColor whiteColor] colorWithAlphaComponent:1];
CPTMutableTextStyle *axisTextStyle = [[CPTMutableTextStyle alloc] init];
axisTextStyle.color = [CPTColor whiteColor];
axisTextStyle.fontName = #"Helvetica-Bold";
axisTextStyle.fontSize = 8.0f;
CPTMutableLineStyle *tickLineStyle = [CPTMutableLineStyle lineStyle];
tickLineStyle.lineColor = [CPTColor whiteColor];
tickLineStyle.lineWidth = 2.0f;
CPTMutableLineStyle *gridLineStyle = [CPTMutableLineStyle lineStyle];
tickLineStyle.lineColor = [CPTColor blackColor];
tickLineStyle.lineWidth = 1.0f;
// 2 - Get the graph's axis set
CPTXYAxisSet *axisSet = (CPTXYAxisSet *) self.hostView.hostedGraph.axisSet;
// 3 - Configure the x-axis
// axisSet.xAxis.labelingPolicy = CPTAxisLabelingPolicyNone;
// axisSet.xAxis.title = #"";
// axisSet.xAxis.labelAlignment = CPTAlignmentRight;
// axisSet.xAxis.titleTextStyle = axisTitleStyle;
// axisSet.xAxis.titleOffset = 38.0f;
// axisSet.xAxis.axisLineStyle = axisLineStyle;
// axisSet.xAxis.labelTextStyle = axisTextStyle;
CGFloat dateCount = [self.arrayData count];
NSMutableSet *xLabels = [NSMutableSet setWithCapacity:dateCount];
NSMutableSet *xLocations = [NSMutableSet setWithCapacity:dateCount];
NSInteger i = 0;
for (ResolutionData *d in self.arrayData)
{
CPTAxisLabel *label = [[CPTAxisLabel alloc] initWithText:[[d.appName componentsSeparatedByString:#"-"]objectAtIndex:0] textStyle:axisSet.xAxis.labelTextStyle];
// [label setRotation:45.0];
CGFloat location = i++;
label.tickLocation = CPTDecimalFromCGFloat(location);
label.offset = axisSet.xAxis.majorTickLength;
if (label) {
[xLabels addObject:label];
[xLocations addObject:[NSNumber numberWithFloat:location]];
}
}
axisSet.xAxis.axisLabels = xLabels;
axisSet.xAxis.majorTickLocations = xLocations;
// 4 - Configre the y-axis
CPTAxis *y = axisSet.yAxis;
y.title = #"count";
y.labelAlignment = CPTAlignmentCenter;
y.titleTextStyle = axisTitleStyle;
y.titleOffset = -40.0f;
y.axisLineStyle = axisLineStyle;
y.majorGridLineStyle = gridLineStyle;
y.labelingPolicy = CPTAxisLabelingPolicyNone;
y.labelTextStyle = axisTextStyle;
y.labelOffset = 16.0f;
y.majorTickLineStyle = axisLineStyle;
// y.majorTickLength = 4.0f;
// y.minorTickLength = 2.0f;
y.tickDirection = CPTSignPositive;
NSInteger majorIncrement = 20;
NSInteger minorIncrement = 10;
CGFloat yMax = 100.0f; // should determine dynamically based on max price
NSMutableSet *yLabels = [NSMutableSet set];
NSMutableSet *yMajorLocations = [NSMutableSet set];
NSMutableSet *yMinorLocations = [NSMutableSet set];
int x =1;
for (NSInteger j = minorIncrement; j <= yMax; j += minorIncrement) {
NSUInteger mod = j % majorIncrement;
if (mod == 0) {
CPTAxisLabel *label = [[CPTAxisLabel alloc] initWithText:[NSString stringWithFormat:#"%i", x] textStyle:y.labelTextStyle];
[label setAlignment:CPTAlignmentTop];
NSDecimal location = CPTDecimalFromInteger(j);x++;
label.tickLocation = location;
label.offset = -y.majorTickLength - y.labelOffset;
if (label) {
[yLabels addObject:label];
}
[yMajorLocations addObject:[NSDecimalNumber decimalNumberWithDecimal:location]];
} else {
[yMinorLocations addObject:[NSDecimalNumber decimalNumberWithDecimal:CPTDecimalFromInteger(j)]];
}
}
y.axisLabels = yLabels;
y.majorTickLocations = yMajorLocations;
y.minorTickLocations = yMinorLocations;
}
Please help me.
Create a new y-axis object, configure it as desired, and add it to the axis set.
axisSet.axes = [NSArray arrayWithObjects:x, y, y2, nil];
If you want a different scale for the right y-axis, you need another plot space. Create a new one, configure it, set the xRange to the same xRange as the default plot space, and add it to the graph. Make sure the new y-axis has its plotSpace set to the new plot space object.
CPTXYPlotSpace *oldPlotSpace = (CPTXYPlotSpace *)graph.defaultPlotSpace;
CPTXYPlotSpace *newPlotSpace = [[[CPTXYPlotSpace alloc] init] autorelease];
newPlotSpace.xRange = oldPlotSpace.xRange;
newPlotSpace.yRange = [CPTPlotRange plotRangeWithLocation:/* location */
length:/* length */];
[graph addPlotSpace:linearPlotSpace];
See the "Axis Demo" and "Plot Space Demo" in the Plot Gallery example app for sample code.

Problems with legend in Core-Plot (pieChart)

I have a problem drawing the legend of a pieChart with Core-Plot, because the name of each element of the chart in the legend is always the identifier of the CPTPieChart. Can someone help me? Thanks.
This is the source code:
-(void)constructPieChart {
// Create pieChart from theme
//[pieGraph applyTheme:theme];
pieChartView.hostedGraph = pieGraph;
pieGraph.plotAreaFrame.masksToBorder = YES;
pieGraph.paddingLeft = 0;
pieGraph.paddingTop = 20.0;
pieGraph.paddingRight = 0;
pieGraph.paddingBottom = 60.0;
pieGraph.axisSet = nil;
// Prepare a radial overlay gradient for shading/gloss
CPTGradient *overlayGradient = [[[CPTGradient alloc] init] autorelease];
overlayGradient.gradientType = CPTGradientTypeRadial;
overlayGradient = [overlayGradient addColorStop:[[CPTColor blackColor] colorWithAlphaComponent:0.0] atPosition:0.0];
overlayGradient = [overlayGradient addColorStop:[[CPTColor blackColor] colorWithAlphaComponent:0.3] atPosition:0.9];
overlayGradient = [overlayGradient addColorStop:[[CPTColor blackColor] colorWithAlphaComponent:0.7] atPosition:1.0];
// Add pie chart
piePlot = [[CPTPieChart alloc] init];
piePlot.dataSource = self;
piePlot.delegate = self;
piePlot.pieRadius = 80.0;
piePlot.identifier = #"Pie Chart 2";
piePlot.startAngle = M_PI_2;
piePlot.sliceDirection = CPTPieDirectionClockwise;
piePlot.borderLineStyle = [CPTLineStyle lineStyle];
//piePlot.sliceLabelOffset = 5.0;
piePlot.overlayFill = [CPTFill fillWithGradient:overlayGradient];
[pieGraph addPlot:piePlot];
pieGraph.title=#"GRAFICA SECTORES";
[piePlot release];
// Add some initial data
NSMutableArray *contentArray = [NSMutableArray arrayWithObjects:
[NSNumber numberWithDouble:20.0],
[NSNumber numberWithDouble:40.0],
[NSNumber numberWithDouble:30.0],
[NSNumber numberWithDouble:23],
[NSNumber numberWithDouble:60.0],
nil];
self.dataForChart = contentArray;
// Add legend
CPTLegend *theLegend = [CPTLegend legendWithGraph:pieGraph];
theLegend.numberOfColumns = 2;
theLegend.fill = [CPTFill fillWithColor:[CPTColor whiteColor]];
theLegend.borderLineStyle = [CPTLineStyle lineStyle];
theLegend.cornerRadius = 5.0;
pieGraph.legend = theLegend;
pieGraph.legendAnchor = CPTRectAnchorBottom;
pieGraph.legendDisplacement = CGPointMake(0.0, 30.0);
}
So in the legend I have always "Pie Chart 2".
PS: Sorry because of my poor english.
You need to add this method to your datasource:
-(NSString *)legendTitleForPieChart:(CPTPieChart *)pieChart
recordIndex:(NSUInteger)index;
It will be called for each index (corresponding to each pie slice). Simply return the correct title string for each one.

Problems Running Core Plot Tutorial

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
None of these errors are caused by #import problems. That tutorial is known to be somewhat out of date and some parts of the Core Plot framework have changed.
The majorIntervalLength property expects an NSDecimal, not NSDecimalNumer. Core Plot includes several utility functions that convert other types to NSDecimal such as CPDecimalFromString and CPDecimalFromDouble.
axisSet.xAxis.majorIntervalLength = CPDecimalFromString(#"5");
The axisLabelOffset property has been renamed to labelOffset.
The third error is caused by two things. Both UIView and CPLayer (the root class for all Core Plot layers) having an -initWithFrame: method. Because -alloc returns an id, the compiler doesn't know which -initWithFrame: to use and sometimes guesses wrong. You can fix it with a typecast. Also, plot spaces are not layers; just get the bounds of the graph.
CPScatterPlot *xSquaredPlot = [[(CPScatterPlot *)[CPScatterPlot alloc] initWithFrame:graph.bounds] autorelease];
// request for member 'axisLabelOffset' in something not a structure or union
... means that the complier doesn't recognize the name provided in the dot syntax as belonging to the object. Typos are a common cause of this error. Another is not properly importing the header for class preceding the dot.
//SAYING INCOMPATIBLE TYPE FOR AURGUMENT 1 'setMajorIntervalLength'
This means that the property majorIntervalLength does not take a NSDecimalNumber.
I'm going to say that all your problems are caused by problems with #import statements. You not importing headers where you should be and the complier doesn't understand what symbol goes with which class.
There is a divide by zero error in your -numberForPlot:field:recordIndex: method. When index == 25, the statement 1/val will blow up.
Follow this Tute
This Ray's tutorial is really helpful.