Я пытаюсь выучить CorePlot. Я нашел пример кода из «codejunkster», которому следовал до «T», но он не работает. Я сузил его до метода numberForPlot. Код ниже. Ни одно из условий не выполняется, и я не могу понять, почему.
-(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];
}
В соответствии с руководством ниже приведен фрагмент кода, который определяет 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];