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:
@@ -205,13 +205,21 @@ 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
|
||||||
ForEach(history.points) { point in
|
// Swift Charts merges every station's points into ONE polyline
|
||||||
LineMark(
|
// (points connect across stations, so only the first station's line
|
||||||
x: .value("Date", point.date),
|
// is recognisable). The outer ForEach keeps one chart with N series;
|
||||||
y: .value("Price", point.pence)
|
// per-mark foregroundStyle then colours each series from the palette.
|
||||||
)
|
Chart {
|
||||||
.foregroundStyle(seriesColor(index(of: history.stationID)))
|
ForEach(displaySeries) { history in
|
||||||
|
ForEach(history.points) { point in
|
||||||
|
LineMark(
|
||||||
|
x: .value("Date", point.date),
|
||||||
|
y: .value("Price", point.pence),
|
||||||
|
series: .value("Station", history.name)
|
||||||
|
)
|
||||||
|
.foregroundStyle(seriesColor(index(of: history.stationID)))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
.chartXAxis {
|
.chartXAxis {
|
||||||
|
|||||||
Reference in New Issue
Block a user