ChartsOrg/Charts

Barchart Animation type easeInBack crashes

Open

#3.340 aberto em 14 de mar. de 2018

Ver no GitHub
 (3 comments) (1 reaction) (0 assignees)Swift (6.009 forks)batch import
bughelp wanted

Métricas do repositório

Stars
 (28.002 stars)
Métricas de merge de PR
 (Nenhuma PRs mesclada em 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

Guia do colaborador