2013-02-07 90 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

謝謝,我會那樣做的。同時解決方法的任何想法? –