Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 showing.

like image 782
Chris Avatar asked Dec 12 '22 09:12

Chris


2 Answers

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.

like image 141
whyoz Avatar answered Dec 14 '22 23:12

whyoz


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.

like image 22
Eric Skroch Avatar answered Dec 14 '22 22:12

Eric Skroch