ChartsOrg/Charts

Barchart Animation type easeInBack crashes

Open

#3,340 opened on Mar 14, 2018

View on GitHub
 (3 comments) (1 reaction) (0 assignees)Swift (6,009 forks)batch import
bughelp wanted

Repository metrics

Stars
 (28,002 stars)
PR merge metrics
 (No merged PRs in 30d)

Description

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

Contributor guide