I'm trying to detect TapGesture on BarMark on SwiftUI Chart (iOS 17.0), but unsuccessfully.
I'm aware that I can use the chartXSelection modifier but it reacts on drag gestures which collides with scrolling and leads to not very best user experience.
Do you have any suggestions? Thanks
var body: some View {
Chart {
ActivitiesChartContent(activities: $activities)
HistoryDataChartContent(quantities: $quantities)
}
.chartScrollableAxes(.horizontal)
.chartXSelection(value: $rawSelectedDate)
.onChange(of: rawSelectedDate) { oldValue, newValue in
guard let newValue,
let activity = activities.first(where: { ($0.startDate...$0.endDate).contains(newValue) }) else { return }
onTap?(activity)
}
}
I tried:
- Overriding
chartGesture, but I couldn't find a way to detectTapGesturelocation. - Using
chartOverlayas suggested in other threads, but it doesn't contain the whole frame so it can't detect the real location