So I'm trying to draw a bar chart using the code below:
HStack(alignment: .bottom) {
ForEach(0..<values.count) { idx in
let max = values.max() ?? 0
VStack {
Text(labels[idx])
.font(.caption)
.rotationEffect(.degrees(-60))
RoundedRectangle(cornerRadius: 5)
.fill(Color.white)
.frame(width: 20, height: CGFloat(values[idx]) / CGFloat(max) * geo.size.height * 0.6)
Text(xAxisLabels[idx])
.font(.caption)
}
}
}.frame(maxWidth: .infinity, maxHeight: .infinity)
.cornerRadius(10)
.padding(.bottom, 20)
}
Note line:
.frame(width: 20, height: CGFloat(values[idx]) / CGFloat(max) * geo.size.height * 0.6)
I am dynamically assigning the height to the bar chart from the values from HealthKit (The 'values' variable).
I'm just wondering is there anyway I could fix this issue? I have prior versions where the bar chart can be displayed using static variables and from what I can understand from the error it doesn't like the fact that the potential height is not static.