I'm trying to create a Range chart that looks like a native iOS heart rate chart but with some additional lines on it. . I found the example here https://github.com/jordibruin/Swift-Charts-Examples
I tried to modify my chart by adding a GeometryReader from another chart. FindElement works fine but nothing happens after. So maybe you know a fast answer what should I fix or add to show that line? Or maybe can take a piece of advice on how to get it done using another solution.
private var chart: some View {
Chart(data, id: \.weekday) { dataPoint in
Plot {
BarMark(
x: .value("Day", dataPoint.weekday, unit: .day),
yStart: .value("BPM Min", dataPoint.dailyMin),
yEnd: .value("BPM Max", dataPoint.dailyMax),
width: .fixed(isOverview ? 8 : barWidth)
)
.clipShape(Capsule())
.foregroundStyle(chartColor.gradient)
}
.accessibilityLabel(dataPoint.weekday.weekdayString)
.accessibilityValue("\(dataPoint.dailyMin) to \(dataPoint.dailyMax) BPM")
.accessibilityHidden(isOverview)
}
.chartOverlay { proxy in
GeometryReader { geo in
Rectangle().fill(.clear).contentShape(Rectangle())
.gesture(
SpatialTapGesture()
.onEnded { value in
let element = findElement(location: value.location, proxy: proxy, geometry: geo)
if selectedElement?.weekday == element?.weekday {
// If tapping the same element, clear the selection.
selectedElement = nil
} else {
selectedElement = element
}
}
.exclusively(
before: DragGesture()
.onChanged { value in
selectedElement = findElement(
location: value.location,
proxy: proxy,
geometry: geo
)
}
)
)
}
}
.chartXAxis {
AxisMarks(values: .stride(by: ChartStrideBy.day.time)) { _ in
AxisTick().foregroundStyle(.white)
}
}
.accessibilityChartDescriptor(self)
.chartYAxis(.visible)
.chartXAxis(.visible)
.frame(height: isOverview ? Constants.previewChartHeight : Constants.detailChartHeight)
}