'SwiftUI Chart line with rounded corners

I'm trying to do a chart with rounded corners like the picture below.

Chart

I've tried the following code in Path:

.stroke(style: StrokeStyle(lineWidth: 2, lineCap: .round))

and

.stroke(Color.accentColor, style: StrokeStyle(lineWidth: 2, lineJoin: .round))

Nothing seems to work, is this possible? Any option I try in both lines always shows the graph the same way (picture below) enter image description here I'm using SwiftUI, swift 5, iOS 15. Thanks in advance.



Solution 1:[1]

A line width of 2 is going to have barely visible rounding, you're looking at a circle of one point radius. These two lines are drawn with and without rounded joins at a line width of 2:

enter image description here

And here with a line width of 10:

enter image description here

If your line changes direction sharply then it's going to have a point on it, because that's the shape of your data. You can cut off the points by experimenting with the miter limit on the stroke style. If you want to smooth out your data then you'll need to look at some sort of interpolation, but that may not be appropriate depending on what you're modelling. See "smooth interpolation" [here] for an example. (https://developer.apple.com/documentation/accelerate/working_with_vectors)

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 jrturton