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,15 +205,23 @@ struct TrendsView: 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
|
||||
LineMark(
|
||||
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)))
|
||||
}
|
||||
}
|
||||
}
|
||||
.chartXAxis {
|
||||
AxisMarks(values: .stride(by: .day, count: xStride)) { _ in
|
||||
AxisGridLine()
|
||||
|
||||
Reference in New Issue
Block a user