views:

1081

answers:

2

Hi all,

I'm getting the above error when compiling an iPhone app using the core-plot framework. I have this view controller's view linked to a CPLayerHostingView in IB. Here's the sample code from the viewDidLoad() function.

- (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)];

    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.axisLabelOffset = 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.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 setPlotSymbol: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];
}

The trouble lines are these:

CPScatterPlot *xSquaredPlot = [[[CPScatterPlot alloc] initWithFrame:graph.defaultPlotSpace.bounds] autorelease];
CPScatterPlot *xInversePlot = [[[CPScatterPlot alloc] initWithFrame:graph.defaultPlotSpace.bounds] autorelease];

It's saying there is no 'bounds' from graph.defaultPlotSpace. Anybody run into this as well?

+1  A: 

Try those calls with bracket syntax.

CPScatterPlot *xSquaredPlot = [[[CPScatterPlot alloc] initWithFrame:[[graph defaultPlotSpace] bounds]] autorelease];
CPScatterPlot *xInversePlot = [[[CPScatterPlot alloc] initWithFrame:[[graph defaultPlotSpace] bounds]] autorelease];
Brandon Walkin
+1  A: 

The CPXYPlotSpace you're getting back as the graph's defaultPlotSpace is a subclass of CPPlotSpace, which is just a subclass of NSObject. None of those classes define a bounds property. Instead, the CPXYPlotSpace has you set ranges via the CPPlotRange objects, as you see in the first two lines after retrieving the defaultPlotSpace.

The proper way to do what you want would be to allocate the plots and just use -init, rather than -initWithFrame:. When these plots are added to the graph, I believe that they are automatically sized based on the plot space. Alternatively, you can use -initWithFrame: and use the graph's frame.

If you would like to see a convenience method that returns the bounds from a CPXYPlotSpace, let us know in the mailing list.

Brad Larson
Thanks for the info, Brad. I will go with your suggestion here. I basically did a straight copy/paste from the switchonthecode.com, and came back with those errors.The convenience method would be nice, but probably unnecessary if I can grab the frame from the graph object instead.
Steve-o
Unfortunately, the API on the framework is still evolving, so the switchonthecode.com example no longer works out of the box with the current version of the framework. Some slight adjustments are required to bring it in line with the current API. Sorry about that.
Brad Larson