John Cogan
John Cogan

Reputation: 1060

How to format the text of the y Axis

The text of my y Axis is displaying with a decimal point but I need this to show as an integer value. E.g. 3000.0 should display as 3000

enter image description here

The yAxis interval length though is declared in the source as

@property (nonatomic, readwrite, assign) NSDecimal majorIntervalLength;

How can I achieve this?

The y Axis ticks are calculated by

NSString *yMajorIntervalLength = [[NSNumber numberWithFloat:(yMaxRange / 10)] stringValue];
CPTXYAxis *y = axisSet.yAxis;
y.axisLineStyle               = nil;
y.majorTickLineStyle          = nil;
y.minorTickLineStyle          = nil;
y.majorIntervalLength         = CPTDecimalFromString(yMajorIntervalLength);

Upvotes: 0

Views: 50

Answers (2)

Konstantin
Konstantin

Reputation: 156

You can try something like this

[yMajorIntervalLength stringByDeletingPathExtension] :)

or

NSRange dotRange = [yMajorIntervalLength rangeOfString:@"." options:NSBackwardsSearch];
if (dotRange.location != NSNotFound)
    test = [yMajorIntervalLength substringToIndex:dotRange.location];

Upvotes: 0

Albara
Albara

Reputation: 1296

Try -setMaximumFractionDigits: and -setMinimumFractionDigits:

These configure the number of digits after the decimal separator.

Upvotes: 1

Related Questions