0
votes

I have a line chart. How can I make the yAxis values to be multiple of 100 or 1000 or X?

So the chart displays £0, £400, £800, £1000 instead of what's on the screenshot.

I don't want to use the value formatter stringForValue and round the 398 to 400 as it's not correct. I want the lines to be on the 400, 800 etc.

Also when the chart has leftAxis.axisMinimum not equal 0 (eg. -100) how can I force the chart to display the first (lowest) line at 0 not at actual axisMinimum?

enter image description here

1

1 Answers

0
votes

make min and max axis to divisible by 400 and set the granularity and label count

let min: Int = (minY / 400) * 400 - 400 // make min divisible by 400
    let max: Int = (maxY / 400) * 400 + 400 // make max divisible by 400
    let count: Int = (max / 400) + (0 - min / 400) + 1 // + 1 for 0 label
    chart.leftAxis.granularity = 400
    chart.leftAxis.setLabelCount(count, force: true)
    chart.leftAxis.axisMinimum = Double(min)
    chart.leftAxis.axisMaximum = Double(max)

and just add first entry with 0 y value

ChartDataEntry(x: 0, y: 0)