LineMark Does Not Respect .foregroundStyle Color choice

Working through the new Swift Chart framework and I am noticing LineMark does not seem to want to respect .foregroundStyle(.pink) (or any respective color) for more than one line.

Apple's own Chart page lists an example that, when copied into Xcode 14 (beta 1) it does not render in preview as it does in their screenshot

Data used:

struct ProfitOverTime {
	var week: Int
	var profit: Double
}

let departmentAProfile: [ProfitOverTime] = [
	.init(week: 1, profit: 21.5),
	.init(week: 2, profit: 19.2),
	.init(week: 3, profit: 18.4),
	.init(week: 4, profit: 21.0),
	.init(week: 5, profit: 19.7),
	.init(week: 6, profit: 14.7),
	.init(week: 7, profit: 22.1),
	.init(week: 8, profit: 18.0)
]

let departmentBProfile: [ProfitOverTime] = [
	.init(week: 1, profit: 5.7),
	.init(week: 2, profit: 12.0),
	.init(week: 3, profit: 11.9),
	.init(week: 4, profit: 18.0),
	.init(week: 5, profit: 15.9),
	.init(week: 6, profit: 16.7),
	.init(week: 7, profit: 12.1),
	.init(week: 8, profit: 19.0)
]

Content View:

struct ContentView: View {
    var body: some View {
		Chart {
			ForEach(departmentAProfile, id: \.week) {
				LineMark(
					x: .value("Week", $0.week),
					y: .value("Profit A", $0.profit)
				).foregroundStyle(.green)
			}

			ForEach(departmentBProfile, id: \.week) {
				LineMark(
					x: .value("Week", $0.week),
					y: .value("Profit B", $0.profit)
				)
				.foregroundStyle(.green)
			}

			RuleMark(
				y: .value("Threshold", 20.0)
			)
			.foregroundStyle(.teal)
		}
    }
}

Produces

Answered by zt01zg in 716525022

I may have solved this by using LineMark's series property (as detailed here).

I see 2 colors, just as you specified: 2 are green, one is teal… There is no pink in your code.

Accepted Answer

I may have solved this by using LineMark's series property (as detailed here).

LineMark Does Not Respect .foregroundStyle Color choice
 
 
Q