In the iOS Chart Framework the y-values in the chart are repeating. As shown in the picture below there are multiple 0's and 1's in the chart. Is there anyway I can customize this chart so there aren't any repeating y-values. So in this scenario ideally the y-values should be 1,2,3,4,5. I just don't want the y-values to repeat itself.
Asked
Active
Viewed 2,434 times
2

Harish
- 1,374
- 17
- 39
-
Looks like whatever is formatting the y-axis values is rounding to 0 decimal places. – Douglas Hill May 06 '16 at 03:04
2 Answers
7
you could also try:
/// When true, axis labels are controlled by the `granularity` property.
/// When false, axis values could possibly be repeated.
/// This could happen if two adjacent axis values are rounded to same value.
/// If using granularity this could be avoided by having fewer axis values visible.
public var granularityEnabled = false
and set yAxis.granularity
= some value

Wingzero
- 9,644
- 10
- 39
- 80
-
-
1Thank you, I added these 2 lines and it worked like a charm ! leftAxis.granularityEnabled = true leftAxis.granularity = 1 – Lilo Mar 29 '18 at 15:18
2
That's because the y-axis values currently have fractional values between 0 and 1. Those numbers are really 0, 0.2, 0.4, 0.6, 0.8, and 1. To format them properly try modifying the valueFormatter
on the ChartYAxis
:
let yAxis = chart.leftAxis
let yAxisValueFormatter = NSNumberFormatter()
yAxisValueFormatter.usesSignificantDigits = true // This will tell the formatter to display the decimal places
yAxis.valueFormatter = yAxisValueFormatter
The current range of the y-axis is 0 to 1 with 6 labels. If you add values greater than 1 then the range will automatically adjust. You can also use customAxisMax
to force the max value if the current range is not suitable.

ospr
- 1,650
- 2
- 17
- 21