开发者

core-plot remove decimal points from axis labels

Can someone tell me how to remove the decimal points from the Axis labels? Instead of 10.0 I'd like to have only 10 show开发者_JS百科ing.


CPTXYAxis *x = axisSet.xAxis;
NSNumberFormatter *Xformatter = [[NSNumberFormatter alloc] init];
[Xformatter setGeneratesDecimalNumbers:NO];
[Xformatter setNumberStyle:NSNumberFormatterDecimalStyle];
x.labelFormatter = Xformatter;
[Xformatter release];

This will take care of the decimals on the x axis as well as add commas with NSNumberFormatterDecimalStyle. You will need to do the same for the y axis.

There are a ton of things you can do with NSNumberFormatter, including converting numbers into dollars using:

[Xformatter setNumberStyle:NSNumberFormatterCurrencyStyle];
//this will add a decimal point again if you put this in the code above

Play around with the Esc key to see all formatting available for setNumberStyle or other methods.


Set the labelFormatter property on the axis to a new formatter. This is a standard NSNumberFormatter object. See Apple's class documentation for details on the options available.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜