I am messing with the new swift charts library and its alignment is a little weird for the x values. When i specify AxisValueLabel(centered: true) the last value gets cut off(December in this case).
If I dont specify center=true, then the x value has leading alignment and it just looks off.
code for graph
struct graphOne: View {
@ObservedObject var vm: CVVM
@State private var position = 30
var frameWidth = UIScreen.screenWidth
var body: some View {
Chart {
ForEach(vm.currentUsage) { empRes in
BarMark(
x: .value("Month", empRes.date, unit: vm.filter),
y: .value("energy", empRes.energyUsage)
)
//.foregroundStyle(.green)
.annotation(position: .top) {
Text("\(empRes.energyUsage)")
.font(.caption)
}
.cornerRadius(5)
}
}
.chartXAxis {
AxisMarks(preset: .aligned, values: vm.currentUsage.map{ $0.date}) { date in
AxisValueLabel(format: vm.chartType == "months" ? .dateTime.month() : .dateTime.day(), centerd: true)
}
}
.chartYAxis {
AxisMarks(position: .leading)
}
.padding()
.frame(width: frameWidth )
}
}