I am trying to learn CorePlot. I found a code example from “codejunkster” that I followed to the “T”, but it is not working. I narrowed it down to the numberForPlot method. The code is below. Neither of the conditions are true and I cannot figure out why.
-(NSNumber *)numberForPlot:(CPTPlot *)plot field:(NSUInteger)fieldEnum recordIndex:(NSUInteger)index
{
if ( [plot.identifier isEqual:@"chocoplot"] )
{
NSDictionary *bar = [self.dataForChart objectAtIndex:index];
if(fieldEnum == CPTBarPlotFieldBarLocation)
{
return [bar valueForKey:BAR_POSITION];
NSLog(@"return [bar valueForKey:BAR_POSITION]");
}
else if(fieldEnum ==CPTBarPlotFieldBarTip){
NSLog(@"return [bar valueForKey:BAR_HEIGHT];");
return [bar valueForKey:BAR_HEIGHT];
}
}
return [NSNumber numberWithFloat:0];
}
Per the tutorial, below is a snippet of code which defines the CPTBarPlot…
// Create bar plot and add it to the graph
CPTBarPlot *plot = [[CPTBarPlot alloc] init] ;
plot.dataSource = self;
plot.delegate = self;
plot.barWidth = [[NSDecimalNumber decimalNumberWithString:@"5.0"]
decimalValue];
plot.barOffset = [[NSDecimalNumber decimalNumberWithString:@"10.0"]
decimalValue];
plot.barCornerRadius = 5.0;
// Remove bar outlines
CPTMutableLineStyle *borderLineStyle = [CPTMutableLineStyle lineStyle];
borderLineStyle.lineColor = [CPTColor clearColor];
plot.lineStyle = borderLineStyle;
// Identifiers are handy if you want multiple plots in one graph
plot.identifier = @"chocoplot";
[self.graph addPlot:plot];
The enum definition changed back in January:
Make sure the
identifiertest is passing. If it is and the compiler still has the old enum values for some reason, try a clean build.