How do I increase the spacing between the labels and the bars?
var body: some View {
if sections.count > 4 {
defaultBody().aspectRatio(1, contentMode: .fill)
} else {
// when there are too little items, aspect ratio above makes the chart look too spaced out, so we don't use it
defaultBody()
}
}
private func defaultBody() -> some View {
Chart(sections) { section in
BarMark(x: .value("Price", section.header.totalPrice * progress),
y: .value("Category", section.header.name))
.foregroundStyle(Theme.accentSec)
.position(by: .value("Alignment", 0))
}
.chartLegend(.hidden)
.chartXAxis(.hidden)
.chartXScale(domain: .automatic(dataType: Float.self, modifyInferredDomain: { $0 = [0, max] }))
.chartYAxis {
AxisMarks { _ in
AxisValueLabel()
.foregroundStyle(Color.black)
}
}
.onAppear {
animateChart()
}
}