The main problem is that the fieldEnum
of that delegate method is not doing what you think. It will either have the value of CPTBarPlotFieldBarLocation
(the 'x' axis location) or CPTBarPlotFieldBarTip
(the bar height), so these should be the cases used in the switch statement. The idx
refers to the specific bar.
Here I have put the heights of the bars in a property of the data source object called plotData
.
self.plotData = @[@(1), @(2), @(3), @(4)];
Then you can implement the delegate method like this,
-(NSNumber*) numberForPlot:(CPTPlot *)plot field:(NSUInteger)fieldEnum recordIndex:(NSUInteger)idx {
switch ( fieldEnum ) {
case CPTBarPlotFieldBarLocation:
return @(idx);
break;
case CPTBarPlotFieldBarTip:
return [plotData objectAtIndex:idx];
break;
default:
break;
}
return nil;
}