Question

I started with core-plot now and came to some problems. I followed the tutorial from this page: http://www.switchonthecode.com/tutorials/using-core-plot-in-an-iphone-application

and completed with the instructions from this page: http://code.google.com/p/core-plot/wiki/UsingCorePlotInApplications (such as -all_load).

But I still have some problems, I get the following errors:

error: incompatible type for argument 1 of 'setMajorIntervalLength:'
error: request for member 'axisLabelOffset' in something not a structure or union
error: incompatible type for argument 1 of 'setMajorIntervalLength:'
error: request for member 'axisLabelOffset' in something not a structure or union
error: request for member 'bounds' in something not a structure or union
error: request for member 'defaultPlotSymbol' in something not a structure or union
error: request for member 'bounds' in something not a structure or union

Anyone who knows what I am doing wrong? This is my code:

- (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 = [NSDecimalNumber decimalNumberWithString:@"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.axisLabelOffset = 3.0f;

    axisSet.yAxis.majorIntervalLength = [NSDecimalNumber decimalNumberWithString:@"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.axisLabelOffset = 3.0f;

    CPScatterPlot *xSquaredPlot = [[[CPScatterPlot alloc]
                                    initWithFrame:graph.defaultPlotSpace.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 alloc]
                                    initWithFrame:graph.defaultPlotSpace.bounds] autorelease];
    xInversePlot.identifier = @"X Inverse Plot";
    xInversePlot.dataLineStyle.lineWidth = 1.0f;
    xInversePlot.dataLineStyle.lineColor = [CPColor blueColor];
    xInversePlot.dataSource = self;
    [graph addPlot:xInversePlot];
}
Was it helpful?

Solution

The example you're pointing to is out of date and no longer matches the current API for the Core Plot framework. I'd suggest starting with the sample applications that ship with the framework (in the examples directory), as we've kept those updated to match any API changes.

For example axisLabelOffset has been renamed to labelOffset, defaultPlotSymbol no longer exists (you set the plotSymbol property on a CPPlot instance), the plot space no longer has a bounds property, and you no longer need to use -initWithFrame: for the CPPlot instances.

Again, just use the sample applications that ship with the framework as a template, and work from there. We haven't reached a 1.0 release yet, so the API will change as we stabilize and enhance the framework.

OTHER TIPS

you are getting the incompatible type error because majorIntervalLength expects a NSDecimal and you are returning a NSDecimalNumber. see if this works for those errors:

axisSet.xAxis.majorIntervalLength = [[NSDecimalNumber decimalNumberWithString:@"5"] decimalValue];

for the others are you including the header files somewhere?

set the header search and other link (Users..../framework & -ObjC respectively) 

I guess you are providing Absolute path. If you go through the corePlot Documentation you shall see that they have clearly mentioned "You should give relative path at Header Search path Field"

to learn what is a relative path follow, "http://webdesign.about.com/od/beginningtutorials/a/aa040502a.htm"

get full path of core-plot thru terminal command "mdfind" as below.

In terminal type, mdfind -name coreplot

will get full path name.

Take full path and insert in HEADERS SEARCH PATH

along with above... add -Objc to "Othetr Linker Flags" and add Quartz frame work in "Link Binary With Libraries"

It will WORK :)

ive done the following:

1) added #import "CorePlot-CocoaTouch.h" 2) added the : UIViewController to the .h vc file 3) added the exact same code from CPTest app 4) added the coreplot-cocoatouch framework to my project, set the dependency in target settings, set the header search and other link (Users..../framework & -ObjC respectively) in project settings, added the QuartzCore framework and when i compile i get:

import "CorePlot-CocoaTouch.h" NO SUCH FILE OR DIRECTORY....

i dont understand why its not finding the header files...

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top