2

I am not sure how IOS Charts should behave when there is only 1 value to display, but for me it crashes all the time with the error: fatal error: Index out of range

Here is where the problem is happening:

func stringForValue(_ value: Double, axis: AxisBase?) -> String {
    let period = getXValues()
    return period[Int(value)]
}

value comes as -1.

Did someone had this issue before ?

Or is there a way to display data only when there is minimum 2 values ?

Adrian
  • 19,440
  • 34
  • 112
  • 219

1 Answers1

0
func stringForValue(_ value: Double, axis: AxisBase?) -> String {
            
            let index = Int(value)
            if (index < labels.count && index >= 0 ) {
            return labels[Int(value)]
            }
            return ""
        }
Pandey_Laxman
  • 3,889
  • 2
  • 21
  • 39