I am working on a graph like this in watchKit
.
I have successfully draw line graph like above image according to custom data but I am unable to draw gradient below line graph like above image.
here what I have done:
var points = [CGPoint(x: 0, y: 20),
CGPoint(x: 10, y: 10),
CGPoint(x: 25, y: 25),
CGPoint(x: 45, y: 5),
CGPoint(x: 60, y: 10),
CGPoint(x: 75, y: 0),
CGPoint(x: 90, y: 25),
CGPoint(x: 110, y: 0),
CGPoint(x: 125, y: 25)]
let shape = SKShapeNode(splinePoints: &points,
count: points.count)
shape.strokeColor = UIColor.white
shape.lineWidth = 2
let gradientShader = SKShader(source: "void main() {" +
"float normalisedPosition = v_path_distance / u_path_length;" +
"gl_FragColor = vec4(normalisedPosition, normalisedPosition, 0.0, 1.0);" +
"}")
// shape.strokeShader = gradientShader
addChild(shape)
This will code will draw a graph like this. (like graph is perfect but issue is in gradient also I have tried SKShader
).