English 中文(简体)
核心 1. 准时适当安排
原标题:iPhone CorePlot proper formatting of y-axis

I am using CorePlot to graph a set of data. Data for my x-axis consists of dates, while data for my y-axis consists of floats (which I then turn into NSNumber). I am getting data from a feed, and the feed returns numbers with a large number of decimals, eg: 0.46673718852844, 4.59392222219, 353.1293012045. I m using the following piece of code to properly format y-axis:

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;

在大多数情况下,所有东西都行不通。 然而,有时在轴线上的多个职位上表现出同样的价值。 见以下图象:

“在座的影像描述”/。</p

The values are presented correctly, I would just like to avoid unnecessary (0.466) labels. I ve even tried to round the numbers to 3 decimals in numberForPlot method:

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

}

但标签没有差别。

最佳回答

<代码>系指NumberOfMajorTicks 财产指标识法的使用量。 如果你想三条标准,将其定为3条。 您还可以增加数字格式的最大数字,以避免出现四舍五入的问题。

问题回答

I believe that because you have said that you want 5 major ticks, that is what you are going to get, regardless of how close the y axis values are. If you sense that the values are too close together, you will probably have to adjust your preferredNumberOfMajorTicks property.

在我使用核心位置时,我放弃了自动轴心标签,我把自己的X和轴心标签放在一起。 这是一项比以往更多的工作,但与自己做这项工作的灵活性一样。

What I did here was dynamically set my preferredNumberOfMajorTicks property while the graph is plotted. Since my formatter shows 3 decimal places, I used the following code to change the number of ticks depending on the Y axis range so that the formatter will show a unique value on the axis at each tick. Too many ticks means the decimal places get cut off and there are duplicate values on the Y axis.

            CPTXYAxis *y          = axisSet.yAxis;
            {
                y.preferredNumberOfMajorTicks = round([newYRange.length floatValue]/0.001);
            }

我希望这一帮助。





相关问题
Code sign Error

I have created a new iPhone application.I have two mach machines. I have created the certificate for running application in iPhone in one mac. Can I use the other mac for running the application in ...

ABPersonViewController Usage for displaying contact

Created a View based Project and added a contact to the AddressBook using ABAddressBookRef,ABRecordRef now i wanted to display the added contact ABPersonViewController is the method but how to use in ...

将音频Clips从Peter改为服务器

我不禁要问,那里是否有任何实例表明从Peit向服务器发送音响。 I m不关心电话或SIP风格的解决办法,只是一个简单的袖珍流程......

• 如何将搜查线重新定位?

我正试图把图像放在搜索条左边。 但是,问题始于这里,搜索条线不能重新布署。

热门标签