我正在使用CorePlot繪製一組數據。我的x軸的數據由日期組成,而我的y軸的數據由浮點數組成(然後我變成NSNumber)。我從Feed中獲取數據,並且Feed會返回具有大量小數的數字,例如:0.46673718852844,4.59392222219,353.1293012045。 我使用下面的代碼來正確地格式化Y軸:iPhone CorePlot 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;
在大多數情況下,一切工作正常。但是,有時它會在沿軸的多個位置顯示相同的值。請參見下面的圖片:
的值正確顯示,我只是想避免不必要的(0.466)標籤。我甚至一直在努力,數字四捨五入到3位小數在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];
}
但在標籤中沒有什麼區別。
問題是這不是我的應用程序中的唯一圖形,並且5個刻度通常看起來最好。數字相同的事情 - 三個通常就足夠了,不需要顯示4位數字。啊,猜猜我必須做一些手動設置的圖表。無論如何,感謝 – Maggie
我的解決方案是根據軸範圍動態更改滴答的數量。 – Jackson