Trends: explicit series so each favourite draws its own line

LineMark lacked a series: value, so Swift Charts merged every
station's points into one polyline — only the first station's
line was recognisable. Adding series: per station splits the
chart into N coloured lines (legend colours now match).
This commit is contained in:
FuelBoard Contributor
2026-08-16 10:19:51 +01:00
parent 3416ad563e
commit 9aea478317
+10 -2
View File
@@ -205,15 +205,23 @@ struct TrendsView: View {
} }
private var chart: some View { private var chart: some View {
Chart(displaySeries) { history in // NOTE: each LineMark MUST carry an explicit `series:` without it
// Swift Charts merges every station's points into ONE polyline
// (points connect across stations, so only the first station's line
// is recognisable). The outer ForEach keeps one chart with N series;
// per-mark foregroundStyle then colours each series from the palette.
Chart {
ForEach(displaySeries) { history in
ForEach(history.points) { point in ForEach(history.points) { point in
LineMark( LineMark(
x: .value("Date", point.date), x: .value("Date", point.date),
y: .value("Price", point.pence) y: .value("Price", point.pence),
series: .value("Station", history.name)
) )
.foregroundStyle(seriesColor(index(of: history.stationID))) .foregroundStyle(seriesColor(index(of: history.stationID)))
} }
} }
}
.chartXAxis { .chartXAxis {
AxisMarks(values: .stride(by: .day, count: xStride)) { _ in AxisMarks(values: .stride(by: .day, count: xStride)) { _ in
AxisGridLine() AxisGridLine()