0

I am getting very large numbers to plot on Yaxis. My requirement is if I get 1000 it should convert in 1K,10000 should show 10K and 1000000 should show 1M and so on.How can I achieve this by using NSNumberFormatter? if not please provide any other alternative solution.I am using below code

NSNumberFormatter *numberFormatter = [[NSNumberFormatter alloc] init];

axisSet.yAxis.labelFormatter = numberFormatter;  
axisSet.yAxis.labelAlignment = CPTAlignmentRight;
axisSet.yAxis.majorGridLineStyle = gridLineStyle;
axisSet.yAxis.majorTickLength = 4.0f;
axisSet.yAxis.minorTicksPerInterval = 0.0;
axisSet.yAxis.labelOffset           = 5.0;
Eric Skroch
  • 27,381
  • 3
  • 29
  • 36
Lavi Gupta
  • 39
  • 5

1 Answers1

0

You can use the NSNumberFormatter multiplier property to display values in "K" or "M". You can't switch over to another multiplier with same formatter. If you need to display a large range where it would make sense to do that, you'll need to create a subclass of NSNumberFormatter to format the values. The PiNumberFormatter class in the Core Plot Plot Gallery example app shows how to make a custom number formatter.

Eric Skroch
  • 27,381
  • 3
  • 29
  • 36
  • I referred to this link http://stackoverflow.com/questions/20352541/format-long-numbers-for-axis-labels-core-plot and implemented the method "-(NSString *)stringForObjectValue:(id)coordinateValue". it worked like charm.Thank you so much Eric – Lavi Gupta Oct 29 '15 at 17:51