I have a view where I display data inside a chart with the Charts package in SwiftUI. When I only use LineMark to display my data everything works fine. But when I want to add a PointMark to this chart I get the error, that Xcode cannot compile that view:
The compiler is unable to type-check this expression in reasonable time; try breaking up the expression into distinct sub-expressions.
This is my code:
struct VoltageDataVView: View {
@Binding var yValues: [Double]
@Binding var voltageValues: [[[Double]]]
@Binding var rowIndex: Double
@Binding var rowPoint: Double
var body: some View {
Chart {
ForEach(0..<self.voltageValues.count, id:\.self) { i in
if self.voltageValues[i].count > 0 {
ForEach(0..<self.voltageValues[i][0].count, id:\.self) { j in
LineMark(
x: .value("x1", self.yValues[j]),
y: .value("y1", self.voltageValues[i][Int(self.rowIndex)][j])
)
}
.foregroundStyle(by: .value("value1", i))
}
}
PointMark(x: .value("x-point-row", self.xValues[Int(self.rowPoint)]),
y: .value("y-point-row", self.voltageValues[0][Int(self.rowIndex)][Int(self.rowPoint)]))
}
.chartXScale(domain: self.yValues.min()!...self.yValues.max()!)
.chartXAxisLabel("number of datapoints")
.chartYAxisLabel("y values")
.frame(width: 400, height: 300)
.rotationEffect(.degrees(-90))
.offset(y: 50)
}
}
I have no idea what I can simplify or breakdown there. What can I do to avoid the error?