I am trying to display custom XAxis
labels. If I leave this line without passing the values
it shows correctly
AxisMarks() { value in
but when I update to this to the following it doesn't display anything on the xAxis, although model.xAxisLabels
is correct, and even if I replace with another array it also doesn't display.
AxisMarks(values: model.xAxisLabels) { value in
Chart {
ForEach(model.items) { item in
BarMark(
x: .value("Time", item.period.identifier),
y: .value("Distance", item.distance)
)
}
}
.chartXAxis {
AxisMarks(values: model.xAxisLabels) { value in
AxisValueLabel {
if let stringValue = value.as(String.self) {
Text(stringValue)
}
}
}
}
If I print stringValue I see the following:
AxisValue(_value: Charts.AnyPrimitivePlottable.category("J"), _index: 0, _count: 12)
AxisValue(_value: Charts.AnyPrimitivePlottable.category("F"), _index: 1, _count: 12)
AxisValue(_value: Charts.AnyPrimitivePlottable.category("M"), _index: 2, _count: 12)
AxisValue(_value: Charts.AnyPrimitivePlottable.category("A"), _index: 3, _count: 12)
AxisValue(_value: Charts.AnyPrimitivePlottable.category("M"), _index: 4, _count: 12)
AxisValue(_value: Charts.AnyPrimitivePlottable.category("J"), _index: 5, _count: 12)
AxisValue(_value: Charts.AnyPrimitivePlottable.category("J"), _index: 6, _count: 12)
AxisValue(_value: Charts.AnyPrimitivePlottable.category("A"), _index: 7, _count: 12)
AxisValue(_value: Charts.AnyPrimitivePlottable.category("S"), _index: 8, _count: 12)
AxisValue(_value: Charts.AnyPrimitivePlottable.category("O"), _index: 9, _count: 12)
AxisValue(_value: Charts.AnyPrimitivePlottable.category("N"), _index: 10, _count: 12)
AxisValue(_value: Charts.AnyPrimitivePlottable.category("D"), _index: 11, _count: 12)
Can anyone see what i am doing incorrectly?