iPhone CorePlot正确格式化y轴

Mag*_*gie 7 iphone core-plot

我正在使用CorePlot来绘制一组数据.我的x轴的数据由日期组成,而我的y轴的数据由浮点数组成(然后我将其转换为NSNumber).我从Feed中获取数据,并且Feed返回具有大量小数的数字,例如:0.46673718852844,4.59392222219,353.1293012045.我正在使用以下代码来正确格式化y轴:

NSNumberFormatter *numberFormatter = [[[NSNumberFormatter alloc] init] autorelease];
[numberFormatter setNumberStyle:NSNumberFormatterDecimalStyle];
[numberFormatter setMaximumFractionDigits:3];
[numberFormatter setPositiveFormat:@"###0.000"];    
CPTXYAxis *y = axisSet.yAxis;
y.labelingPolicy = CPTAxisLabelingPolicyAutomatic;
y.minorTicksPerInterval = 1;
y.preferredNumberOfMajorTicks = 5;
y.labelFormatter = numberFormatter;
Run Code Online (Sandbox Code Playgroud)

在大多数情况下,一切正常.但是,有时它会沿轴的多个位置显示相同的值.见下图:

在此输入图像描述

值正确显示,我只想避免不必要的(0.466)标签.我甚至尝试将数字四舍五入到numberForPlot方法中:

if(fieldEnum == CPTScatterPlotFieldY)
{ 
        float floatNum = r.value;
        floatNum *= 1000;
        int intValue = (int) floatNum;
        float decimal = floatNum - intValue;
        if (decimal > 0.5) {
            intValue++;
        }
        floatNum = intValue /1000.0;
        return [NSNumber numberWithFloat:floatNum];

}
Run Code Online (Sandbox Code Playgroud)

但标签没有区别.

Eri*_*och 1

该preferredNumberOfMajorTicks属性告诉标记算法要使用多少个刻度线。如果您需要三个刻度,请将其设置为 3。您还可以增加数字格式化程序的最大小数位数,以避免舍入问题。