gpt4 book ai didi

iPhone CorePlot y 轴的正确格式

转载 作者:行者123 更新时间:2023-12-03 18:40:15 25 4
gpt4 key购买 nike

我正在使用 CorePlot 绘制一组数据的图表。 x 轴的数据由日期组成,而 y 轴的数据由 float 组成(然后我将其转换为 NSNumber)。我从 Feed 获取数据,并且 Feed 返回具有大量小数的数字,例如:0.46673718852844、4.59392222219、353.1293012045。我使用以下代码来正确设置 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;

在大多数情况下,一切正常。但是,有时它会在沿轴的多个位置显示相同的值。见下图:

enter image description here

值显示正确,我只是想避免不必要的(0.466)标签。我什至尝试在 numberForPlot 方法中将数字四舍五入到小数点后 3 位:

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];

}

但是标签没有区别。

最佳答案

preferredNumberOfMajorTicks属性告诉标记算法要使用多少个刻度线。如果您想要三个刻度,请将其设置为 3。您还可以增加数字格式化程序的最大小数位数,以避免舍入问题。

关于iPhone CorePlot y 轴的正确格式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8042261/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com