Search code examples
iosios-charts

iOS -Chart: Y- Axis interval difference between value


I want to make Y-axis interval with a certain difference. Let's say the multiple of 100 or any fix value, currently it draws with their own interval.

I am sharing my formatting code here.

 let leftAxis = chartView.leftAxis
 leftAxis.valueFormatter = IntAxisValueFormatter()
 leftAxis.granularityEnabled = true
 leftAxis.granularity = 1

enter image description here


Solution

  • I am able to solve my challenge, I am adding my fix here. First I calculated the total range then divided them by interval diff and set the LabelCount.

    let totalRange = maxY - minY
    let interval = 100 //Let's say 100 in my case
    leftAxis.setLabelCount(Int(totalRange/interval) + 1, force: true)