Jean
Jean

Reputation: 2625

Core Plot - number of decimal places for plot label

Am trying to plot memory usage using Core plot in an iPhone App. I want the labels in the plot to show six decimal places, but it shows only four, though tI have coded to show 6 using the code snippet below:

    CPTScatterPlot *plotMem = [[CPTScatterPlot alloc] initWithFrame:self.graph.bounds];
    NSNumberFormatter *plotFormatter = [[NSNumberFormatter alloc] init];
    [plotFormatter setNumberStyle:NSNumberFormatterDecimalStyle];
    [plotFormatter setMaximumFractionDigits:6];
    [plotFormatter setPositiveFormat:@"###0.000000"];
    plotMem.labelFormatter = plotFormatter;

Here's a screenshot from the App: enter image description here

It shows the plot labels as 0.1623, 0.1624 etc, though numberForPlot method is returning numbers like 0.161793, 0.161869, 0.162064, etc.

-(NSNumber *) numberForPlot:(CPTPlot *)plot
                  field:(NSUInteger)fieldEnum
            recordIndex:(NSUInteger)index {
        if ( fieldEnum == CPTScatterPlotFieldY ) {
            NSLog(@"Plot memuse %f for index %d",
          myData.memuse, index);
            return [NSNumber numberWithFloat:myData.memuse]; 
    } else {
        return [NSNumber numberWithInt:index];
    } 
}

How do I make the labels for the plots show 6 decimal places? Am I missing something in the code? Please help.

Upvotes: 0

Views: 365

Answers (1)

Ravindra Bagale
Ravindra Bagale

Reputation: 17655

try using setFormatWidth

CPTScatterPlot *plotMem = [[CPTScatterPlot alloc] initWithFrame:self.graph.bounds];
    NSNumberFormatter *plotFormatter = [[NSNumberFormatter alloc] init];
    [plotFormatter setNumberStyle:NSNumberFormatterDecimalStyle];
   [plotFormatterr setFormatWidth:8];
    [plotFormatter setMaximumFractionDigits:6];
    [plotFormatter setPositiveFormat:@"###0.000000"];
    plotMem.labelFormatter = plotFormatter;

Upvotes: 1

Related Questions