kaiserfarrell / core-plot

Automatically exported from code.google.com/p/core-plot
BSD 3-Clause "New" or "Revised" License
0 stars 0 forks source link

Numeric formatting of y-axis labels #506

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
I'm working with Core Plot 1.1 to draw a simple scatter plot in iOS6. I am 
using the following code to properly format my y-axis which then dynamically 
scales to the plot data.

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.

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. If I 
manually change the minimum range to 2 the error disappears.

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. If I change the 
setMaximumSignificantDigits to 3 I get 0.601 which I guess indicates that the 
problem is with the CPTAxisLabelingPolicyAutomatic.

Fig 1, Error in formatting: https://dl.dropbox.com/u/8083213/fig_1.png

Fig 2, No error in formatting: https://dl.dropbox.com/u/8083213/fig_2.png

Original issue reported on code.google.com by helg...@gmail.com on 8 Feb 2013 at 10:53

GoogleCodeExporter commented 8 years ago

Original comment by eskr...@mac.com on 23 Feb 2013 at 10:53

GoogleCodeExporter commented 8 years ago
This issue was closed by revision 8d1bc1865a12.

Original comment by eskr...@mac.com on 27 Feb 2013 at 2:22