我正在尝试使折线图显示从线条到下方的渐变颜色,但我似乎无法让它仅从线条开始。相反,它只是填充给定帧中的整个背景。
我有这个 -图电流
但我想要这个 -想要图表
import SwiftUI
struct Graph: View {
var body: some View {
ZStack{
LineGraph(dataPoints: [1, 0.8, 0.7, 0.5, 0.7, 0.4, 0.5, 0.6, 0.8, 0.4, 0.3, 0.4, 0.5, 0.7, 0.6, 1])
.stroke(Color(#colorLiteral(red: 0.2784313725, green: 0.2901960784, blue: 0.9568627451, alpha: 1)), lineWidth: 2)
}
.frame(width: 124, height: 90, alignment: .center)
.background(LinearGradient(gradient: Gradient(colors: [Color(#colorLiteral(red: 0.4901960784, green: 0.5058823529, blue: 0.9803921569, alpha: 1)), Color(#colorLiteral(red: 1, green: 1, blue: 1, alpha: 1))]), startPoint: .top, endPoint: .bottom))
}
}
struct LineGraph: Shape …
Run Code Online (Sandbox Code Playgroud)