I use charts for my project. However, I now run into a problem that if a dataset is empty I will all report error when I see debug area.
Now I am trying to find a solution to be able to stop creating the chart if the dataset is empty.
the error message I get 25x :
[32865:1852701] [Unknown process name] CGAffineTransformInvert: singular matrix.
for now I have this solution but I don't know if there is a better one.
var gewichtenHond: [GewichtHond] = [] {
didSet {
if self.gewichtenHond.count == 0 {
self.lineChartView.noDataText = "Geen data beschikbaar om een grafiek te tekenen."
} else {
grafiekData(animatieSnelheid: 1.0, typeAnimatie: .easeInBounce)
}
tableView.reloadData()
}
}
override func viewDidLoad() {
super.viewDidLoad()
}
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
getGewichtenHond()
}
func getGewichtenHond() {
let appDelegate = UIApplication.shared.delegate as? AppDelegate
let context = appDelegate?.persistentContainer.viewContext
let hondFetch = NSFetchRequest<NSFetchRequestResult>(entityName: "Hond")
hondFetch.predicate = NSPredicate(format: "hondId = %@", hondId)
let honden = try! context?.fetch(hondFetch)
let hond: Hond = honden?.first as! Hond
self.gewichtenHond = hond.gewichten?.allObjects as! [GewichtHond]
}