Charts: Barchart Animation type easeInBack crashes

Created on 14 Mar 2018  ·  3Comments  ·  Source: danielgindi/Charts

I have extension extension
```
BarChartView {

private class BarChartFormatter: NSObject,IAxisValueFormatter {

    var values : [String]
    required init (values : [String]) {
        self.values = values
        super.init()
    }


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

func setChartValues (xAxisValues : [String] , values : [Double],label : String) {

    var barChartDataEntries = [BarChartDataEntry]()

    for i in 0..<values.count {
        let dataEntry = BarChartDataEntry(x: Double(i), y: values[i])
        barChartDataEntries.append(dataEntry)
    }
    let chartDataSet = BarChartDataSet(values: barChartDataEntries, label: label)
    chartDataSet.colors = ChartColorTemplates.colorful()
    let chartData = BarChartData(dataSet: chartDataSet)

    let formatter = BarChartFormatter(values: xAxisValues)
    let xAxis = XAxis()
    xAxis.valueFormatter = formatter
    self.xAxis.valueFormatter = xAxis.valueFormatter
    self.xAxis.labelPosition = .bottom

    self.data = chartData
   // self.data?.notifyDataChanged()
   // self.notifyDataSetChanged()

    self.animate(xAxisDuration: 2.0, yAxisDuration: 2.0, easingOption: .easeInBack) // Cause  crash

}

}
```

And app crashes here

for j in 0 ..< Int(ceil(Double(dataSet.entryCount) * animator.phaseX)) // Crash here { guard let e = dataSet.entryForIndex(j) as? BarChartDataEntry else { continue }

Fatal error: Can't form Range with upperBound < lowerBound

(lldb) po dataSet.entryCount
12

(lldb) po animator.phaseX
-0.085005447941268492

Please solve this issue

bug help wanted

All 3 comments

I think it is possible that in your project there is a big function that takes time
the time is over

la solution

        DispatchQueue.main.async(execute: {() -> Void in
       self.animate(xAxisDuration: 2.0, yAxisDuration: 2.0, easingOption: .easeInBack) 
        })

I think so,
for j in 0 ..< Int(ceil(Double(dataSet.entryCount) * animator.phaseX))
change for
for j in stride(from: 0, to: Int(ceil(Double(dataSet.entryCount) * animator.phaseX)), by: 1)

@PrashantKT I have the same issue and the snippet that @txoan have posted is working, but it would be great if anyone can check if the solution doesn't introduce new bugs or any other problem. @jjatie @liuxuan30

Was this page helpful?
0 / 5 - 0 ratings

Related issues

kirti0525 picture kirti0525  ·  3Comments

valeIT picture valeIT  ·  3Comments

Shunshine07 picture Shunshine07  ·  3Comments

ahmedsafadii picture ahmedsafadii  ·  3Comments

coop44483 picture coop44483  ·  3Comments