1

I tried setting yAxis to integer using NSNumberFormatter,

yAxis.valueFormatter = NSNumberFormatter()
yAxis.valueFormatter.minimumFractionDigits = 0

but the problem here is I am getting duplicate yAxis values - 0, 1, 2, 2, 3, 4 and 5. How this can be eliminated?

enter image description here

These are the issues I am facing. I tried setting

    barChart.leftAxis.axisMaximum = 5.0
    barChart.leftAxis.axisMinimum = 0.0
    barChart.leftAxis.customAxisMin = 0
    barChart.leftAxis.customAxisMax = 5.0

but not helping any suggestions?

Ash
  • 149
  • 2
  • 15

1 Answers1

1

This cannot be avoided, because you don't allow fraction digit.

minimumFractionDigits = 0 means no decimal if possible, like 2.1 and 2.0, they will result in 2.1 and 2 ( if maximumFractionDigits = 1)

You need to give the information what's the raw value and what's the value of maximumFractionDigits

EDIT:

the y axis label is calculated by default via internal func computeAxisValues

it calculate the interval based on your max and min value, and the label count.

if _yAxis.isForceLabelsEnabled is enabled, then it will read labelCount and just use (max-min)/(labelCount-1) to calculate the interval. It is disabled by default.

When isForceLabelsEnabled is false, it has a small algorithm to calculate what's the proper way to get a good looking number.

Take a look at internal func computeAxisValues to find out what meets your need.

Update for your second part of question:

  1. you should not touch axisMaximum nor min
  2. enable forceLabelsEnabled
  3. change yAxis.labelCount to 6 or 5 or whatever you like
  4. enable xAxis.wordWrapEnabled
Wingzero
  • 9,644
  • 10
  • 39
  • 80
  • Sorry I didn't get you. I don't want to display decimal on my y-Axis. I'll just give you an example. I need to display rating on my yAxis, the rating may varies from 0 to 5, but the value can be [2.1, 4.3, 5, 3.5, 3, 2, 1], something like this. My yAxis should not have decimal showing up. I tried setting barChart.leftAxis.axisMaximum = 5.0 barChart.leftAxis.axisMinimum = 0.0 barChart.leftAxis.customAxisMin = 0 barChart.leftAxis.customAxisMax = 5.0 but not helping. – Ash Oct 21 '15 at 06:37
  • answer updated. you should use `leftAxis.customAxisMin/Max` by the way. – Wingzero Oct 21 '15 at 06:42
  • it's not working. Any work around? Updated the question. – Ash Oct 21 '15 at 07:56
  • answer updated. BTW, you should be able and should read `computeAxisValues`, it gives what all you need – Wingzero Oct 21 '15 at 08:04
  • I have one more question. Is there a way to not to show the value when we have '0' as rating. – Ash Oct 21 '15 at 08:45
  • let us say I get rating as '0' since drawValuesEnabled is enabled it shows '0' on top of the x-axis. Is their a way to avoid it? If value is zero then don't display anything, else whatever the rating we get. – Ash Oct 21 '15 at 09:24
  • simply override drawValues to ignore 0 – Wingzero Oct 21 '15 at 09:38
  • you mean do I need to subclass 'ChartDataRendererBase' and override drawValues? – Ash Oct 21 '15 at 10:07
  • Just the sub class you are using – Wingzero Oct 21 '15 at 10:13
  • Hi.. I need more information on usage of iOS-Chart, is it possible to have some other way of communication? If I get your email or something. – Ash Oct 21 '15 at 10:20
  • Sorry, I just answer questions on github and SO when I have time. But you could try read the code. They give all the information and try http://www.appcoda.com/ios-charts-api-tutorial/ – Wingzero Oct 21 '15 at 10:36
  • Thats Ok, np.. I keep posting questions here.. :) – Ash Oct 21 '15 at 10:57
  • For ignoring '0', can you please brief me, the class where I am drawing the chart is UIViewController's subclass. – Ash Oct 21 '15 at 11:06
  • take a look at the Y axis renderer drawValues – Wingzero Oct 21 '15 at 11:20
  • OK.. will check and get back to you. Thanks – Ash Oct 21 '15 at 12:08
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/92967/discussion-between-ash-and-wingzero). – Ash Oct 21 '15 at 13:16