I'm using the new Swift Charts ( https://developer.apple.com/documentation/charts ) framework to create a bar chart.
Chart {
BarMark(
x: .value("Name", "Item 1"),
y: .value("Count", 2)
)
BarMark(
x: .value("Name", "Item 2"),
y: .value("Count", 9)
)
BarMark(
x: .value("Name", "Item 3"),
y: .value("Count", 4)
)
BarMark(
x: .value("Name", "Item 4"),
y: .value("Count", 12)
)
BarMark(
x: .value("Name", "Item 5"),
y: .value("Count", 6)
)
BarMark(
x: .value("Name", "Item 6"),
y: .value("Count", 5)
)
}
.chartXAxis {
AxisMarks {
AxisGridline()
AxisTick()
AxisLabel()
}
}
On the x-axis I want to skip just the label for every second element. I want to keep the grid lines and ticks. Using stride for values won't work.
Has anyone an idea on how to achieve this?
Thanks.
I was able to fix it myself.
Chart {
BarMark(
x: .value("Name", "Item 1"),
y: .value("Count", 2)
)
BarMark(
x: .value("Name", "Item 2"),
y: .value("Count", 9)
)
BarMark(
x: .value("Name", "Item 3"),
y: .value("Count", 4)
)
BarMark(
x: .value("Name", "Item 4"),
y: .value("Count", 12)
)
BarMark(
x: .value("Name", "Item 5"),
y: .value("Count", 6)
)
BarMark(
x: .value("Name", "Item 6"),
y: .value("Count", 5)
)
}
.chartXAxis {
AxisMarks { value in
AxisGridline()
AxisTick()
if value.index % 2 == 0 {
AxisValueLabel()
}
}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.