0

我试图在 iPhone 应用程序中使用 Core 绘图来绘制内存使用情况。我希望图中的标签显示六位小数,但它只显示四位,尽管我使用下面的代码片段编码为显示 6:

    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;

这是应用程序的屏幕截图: 在此处输入图像描述

它将绘图标签显示为 0.1623、0.1624 等,尽管 numberForPlot 方法返回的数字如 0.161793、0.161869、0.162064 等。

-(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];
    } 
}

如何使绘图的标签显示小数点后 6 位?我在代码中遗漏了什么吗?请帮忙。

4

1 回答 1

1

尝试使用 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;
于 2013-05-22T08:26:43.987 回答