2

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.enter image description here 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.

Harish
  • 1,374
  • 17
  • 39

2 Answers2

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
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