2013-02-07 93 views
0

我正在使用Core Plot 1.1在iOS6中绘制简单的散点图。我正在使用以下代码来正确格式化我的y轴,然后动态缩放到绘图数据。y轴的iOS CorePlot数字格式化

CPTXYAxis *y = axisSet.yAxis; 
y.labelingPolicy    = CPTAxisLabelingPolicyAutomatic; 
y.minorTicksPerInterval  = 3; 
y.preferredNumberOfMajorTicks = 6; 
y.majorGridLineStyle   = majorGridLineStyle; 
y.minorGridLineStyle   = minorGridLineStyle; 

... 

NSNumberFormatter * yformatter = [[NSNumberFormatter alloc] init]; 
[yformatter setUsesSignificantDigits:YES]; 
[yformatter setMaximumSignificantDigits:4]; 
[yformatter setMaximumFractionDigits:1]; 
[yformatter setRoundingMode:NSNumberFormatterRoundCeiling]; 
y.labelFormatter = yformatter; 

然后,我使用maxPlotValue根据要绘制的数据动态更改范围,但将其限制为最小值。

plotSpace.xRange = [CPTPlotRange 
        plotRangeWithLocation:CPTDecimalFromFloat(0) 
        length:CPTDecimalFromFloat(5)]; 
plotSpace.yRange = [CPTPlotRange 
        plotRangeWithLocation:CPTDecimalFromFloat(0) 
        length:CPTDecimalFromFloat(maxPlotValue)]; 

这在大多数情况下,伟大的,但有时我得到一个奇怪的格式错误,如在下面的图1,其中0.6001显示为0.6代替。如果我手动将最小范围更改为2,则错误消失。

我使用4位有效数字的原因是,我可以将数字设置为8000,然后在没有分数的情况下显示它们。如果我将setMaximumSignificantDigits更改为3,则得到0.601,我猜测问题出在CPTAxisLabelingPolicyAutomatic上。

任何帮助,将不胜感激。

图1中,错误格式: https://dl.dropbox.com/u/8083213/fig_1.png

图2,在格式化无错误: https://dl.dropbox.com/u/8083213/fig_2.png

回答

0

这听起来像是在标签计算的舍入误差。请在Core Plot issue tracker上报告。

+0

谢谢,我会那样做的。同时解决方法的任何想法? –