views:

83

answers:

1

I try to plot a Bar Chart with Core-Plot with an Array (content are NSIntegers) given one view before. After transfering the Array in an NSInteger, i must convert it into a NSDecimalNumber, and in this process, my NSInteger (for example 45) becomes "60900224"...

Here's the code extract:

-(NSNumber *)numberForPlot:(CPPlot *)plot field:(NSUInteger)fieldEnum recordIndex:(NSUInteger)index 
{ NSInteger *values = [Werte objectAtIndex:index];
    NSDecimalNumber *num = nil;
    if ( [plot isKindOfClass:[CPBarPlot class]] ) {
        switch ( fieldEnum ) {
            case CPBarPlotFieldBarLocation:
                num = (NSDecimalNumber *)[NSDecimalNumber numberWithUnsignedInteger:index];
                break;
            case CPBarPlotFieldBarLength:
                //num = (NSDecimalNumber *)[NSDecimalNumber numberWithUnsignedInteger:(index+1)*(index+1)];
                num = [NSNumber numberWithInt:values];
                if ( [plot.identifier isEqual:@"Bar Plot 2"] ) 
                    num = [num decimalNumberBySubtracting:[NSDecimalNumber decimalNumberWithString:@"10"]];
                break;
        }

    }
    return num;
}

Thanks for help!!

A: 

NSInteger is not an object type and can't be stored in an NSArray (which your Werte appears to be). You seem to be implicitly converting from a pointer to an integer.

Instead, you should always put NSNumber objects into the array, and then get NSInteger values out of those via integerValue:

NSInteger value = [[Werte objectAtIndex:index] integerValue];
walkytalky
Ok, thank you very much, this was my Problem, with NSNumberFormatter the Bar Chart works!
Jonathan