views:

1029

answers:

4
+1  Q: 

CorePlot problems

Hi,

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];
}

Best regards, Paul Peelen

+2  A: 

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?

John Stallings
Thanks, that solved 2 of the errors.The header files are included included through the .h file. #import "CorePlot-CocoaTouch.h"Regards /Paul
Paul Peelen
also in looking at the CPAxis header file there doesn't appear to be a n axisLabelOffset only a labelOffset?
John Stallings
+5  A: 

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.

Brad Larson
Will do. Thanks for the info.
Paul Peelen
If you need any additional help, don't hesitate to ask on the mailing list: http://groups.google.com/group/coreplot-discuss?hl=en
Brad Larson
Thanks Brad, for the help.
Madhup
A: 

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...

mars
so i manually went to target settings and added header search paths of /Users/me/core=plot/framework + /framework/iPhoneOnly + /framework/Source and now i get:A) Check Dependency = Skipping the file /Users/me/core-plot/framework/CorePlot-CocoaTouch.xcodeproj (unexpected filetype 'wrapper.pb-project'b) Link = ".objc_class_name_CPTheme", referenced from ... (a whole bunch)...
mars
A: 
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"

TriNitroToluene