我正在使用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