Question

I'm drawing a graph in core plot with an automatic naming policy.

My problem is that the numbers in my graph are very high.

For example the axis has 1000000.0 2000000.0 3000000.0

I'd like some way to over write these and make them 1.00m 2.00m and 3.00m

I've looked into the axis delegate but it only returns a bool and not a specific label. I've also explored setting the axis label formatter but that cannot add the 'm' on the end, nor I don't think it can turn the number into a decimal similar to scientific notation without the exponential on the end.

Was it helpful?

Solution

The answer is to set the label formatter on the axis. From a quick look at the documentation for NSNumberFormatter, it seems you should be able to do what you're looking for with a combination of setPositiveFormat, setMultiplier, and setPositiveSuffix.

Something like:

NSNumberFormatter *labelFormatter = [[NSNumberFormatter alloc] init];
[labelFormatter setPositiveFormat:@"#.##"];
[labelFormatter setPositiveSuffix:@"m"];
[labelFormatter setMultiplier:[NSNumber numberWithDouble:0.000001]];
axisSet.yAxis.labelFormatter = labelFormatter;
[labelFormatter release];

FWIW, the call to setPositiveSuffix isn't strictly necessary here - you can just include the "m" in the format string ([labelFormatter setPositiveFormat:@"#.##m"]), and leave that call out if you want. I included it here for the sake of completeness, in case you need to do more complex formatting than this.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top