I have the following Chart
and I can't figure out why the AreaMark
's are transparent.
The area marks are opaque when I move the .symbol
view modifier to the AreaMark
, but then the gradient doesn't work anymore
Any ideas on how to solve this?
struct Ranking: Identifiable {
let name: String
let steps: Int
var id: String { name }
}
let rankings: [Ranking] = [
.init(name: "Tom", steps: 200),
.init(name: "Joseph", steps: 850),
.init(name: "Emil", steps: 700),
.init(name: "Sandra", steps: 100),
.init(name: "Annie", steps: 400),
.init(name: "Teo", steps: 700),
.init(name: "Pär", steps: 400)
]
struct ContentView: View {
let curGradient = LinearGradient(
gradient: Gradient (
colors: [
Color(.blue).opacity(0.1),
Color(.blue).opacity(0.0)
]
),
startPoint: .top,
endPoint: .bottom
)
var body: some View {
VStack() {
Text("Ranking")
Chart {
ForEach(rankings) { element in
LineMark(
x: .value("Name", element.name),
y: .value("Steps", element.steps)
)
.interpolationMethod(.catmullRom)
.foregroundStyle(.blue)
.symbol {
Circle()
.fill(.white)
.frame(width: 20)
.shadow(radius: 2)
}
AreaMark(
x: .value("Name", element.name),
y: .value("Steps", element.steps)
)
.interpolationMethod(.catmullRom)
.foregroundStyle(curGradient)
}
}
.chartYAxis(.hidden)
.chartXAxis {
AxisMarks(position: .top) { value in
AxisValueLabel(verticalSpacing: 20)
}
}
.frame(height: 200)
Spacer()
}
}
}
struct ContentView_Previews: PreviewProvider {
static var previews: some View {
ContentView()
}
}