I’m using Swift Charts to show a scatter plot with multiple PointMarks. When the user selects a point, I attach an annotation to the selected PointMark to show a label like Strike 1.
I expected the annotation to render above all chart marks, but in practice nearby PointMarks can be drawn over the annotation text/background.
Simplified example:
Chart {
ForEach(points.filter { !$0.isSelected }) { point in
PointMark(
x: .value("X", point.x),
y: .value("Y", point.y)
)
.foregroundStyle(.black)
}
if let selectedPoint {
PointMark(
x: .value("X", selectedPoint.x),
y: .value("Y", selectedPoint.y)
)
.foregroundStyle(.orange)
.annotation(position: .top) {
Text("Strike \(selectedPoint.number)")
.padding(.horizontal, 8)
.padding(.vertical, 4)
.background(Capsule().fill(.orange.opacity(0.15)))
}
}
}
screenshots