I'am trying to handle click on annotation in SwiftUI BarMark
var body: some View {
List {
Chart {
ForEach(data) {
BarMark(
x: .value("Mount", $0.mount),
y: .value("Value", $0.value)
)
.foregroundStyle(by: .value("Type", "Series \($0.type)"))
.position(by: .value("Type", $0.type))
.annotation {
HStack {
Rectangle()
.fill(Color.red.opacity(0.2))
.frame(width: 20, height: 20)
.clipShape(Circle())
.onTapGesture {
print("Tapped!") // Never called
}
}
}
}
}
.frame(height: 250)
.labelsHidden()
}
}
I also tried Button with action, Image etc., but it seems like all interactions in annotation are disabled or I don't know..
Apple provides some code for click handle, but I don't know how to use it for strings (Apple has Date in example) and don't have compare bars like me.
Any ideas please?