لدي تمديد
""
عرض BarChart {
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
}
}
""
ويتعطل التطبيق هنا
for j in 0 ..< Int(ceil(Double(dataSet.entryCount) * animator.phaseX)) // Crash here
{
guard let e = dataSet.entryForIndex(j) as? BarChartDataEntry else { continue }
خطأ فادح: لا يمكن تشكيل النطاق مع الجزء العلوي من النطاق <LowerBound
(lldb) po dataSet.entryCount
12
(lldb) po animator.phaseX
-0.085005447941268492
الرجاء حل هذه المشكلة
أعتقد أنه من الممكن أن يكون في مشروعك وظيفة كبيرة تستغرق وقتًا
انتهى الوقت
لا الحل
DispatchQueue.main.async(execute: {() -> Void in
self.animate(xAxisDuration: 2.0, yAxisDuration: 2.0, easingOption: .easeInBack)
})
أنا اعتقد ذلك،
for j in 0 ..< Int(ceil(Double(dataSet.entryCount) * animator.phaseX))
تغير ل
for j in stride(from: 0, to: Int(ceil(Double(dataSet.entryCount) * animator.phaseX)), by: 1)
PrashantKT لدي نفس المشكلة والمقتطف الذي نشرهtxoan يعمل ، ولكن سيكون رائعًا إذا كان بإمكان أي شخص التحقق مما إذا كان الحل لا يقدم أخطاء جديدة أو أي مشكلة أخرى. تضمين التغريدة