简体   繁体   English

iOS CorePlot y轴的数字格式

[英]iOS CorePlot numeric formatting of y-axis

I'm working with Core Plot 1.1 to draw a simple scatter plot in iOS6. 我正在使用Core Plot 1.1在iOS6中绘制一个简单的散点图。 I am using the following code to properly format my y-axis which then dynamically scales to the plot data. 我正在使用以下代码正确格式化我的y轴,然后将其动态缩放到绘图数据。

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;

Then I dynamically change the range based on the data to be plotted using maxPlotValue but bound it to a minimum. 然后,我根据要使用maxPlotValue绘制的数据动态更改范围,但将其限制为最小值。

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

This works great in most cases but sometimes I get a strange formatting error like in the below fig 1 where 0.6001 is displayed in stead of 0.6. 在大多数情况下,这种方法效果很好,但有时会出现奇怪的格式错误,如下图1所示,其中显示的是0.6001而不是0.6。 If I manually change the minimum range to 2 the error disappears. 如果我手动将最小范围更改为2,错误消失。

The reason I'm using 4 significant digits is that I can have numbers up to 8000 and then they are displayed without the fraction. 我使用4个有效数字的原因是,我可以拥有最多8000个数字,然后显示时不带小数。 If I change the setMaximumSignificantDigits to 3 I get 0.601 which I guess indicates that the problem is with the CPTAxisLabelingPolicyAutomatic. 如果我将setMaximumSignificantDigits更改为3,则得到0.601,我猜这表明问题出在CPTAxisLabelingPolicyAutomatic。

Any help on this would be greatly appreciated. 任何帮助,将不胜感激。

Fig 1, Error in formatting: https://dl.dropbox.com/u/8083213/fig_1.png 图1,格式错误: https : //dl.dropbox.com/u/8083213/fig_1.png

Fig 2, No error in formatting: https://dl.dropbox.com/u/8083213/fig_2.png 图2,格式化没有错误: https : //dl.dropbox.com/u/8083213/fig_2.png

This sounds like a rounding error in the labeling calculations. 这听起来像是标签计算中的舍入错误。 Please report it on the Core Plot issue tracker . 请在Core Plot 问题跟踪器上报告它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM