Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 203
lopes710 Avatar asked Oct 25 '25 12:10

lopes710


1 Answers

You can use .interpolationMethod(.cardinal) on your LineMark.

Example:

Chart {
    ForEach(data, id: \.id) { item in
        LineMark(
            x: .value("Day", item.date),
            y: .value("Mood", item.value)
        ).lineStyle(.init(lineWidth: 6))
         .interpolationMethod(.cardinal)
     }
}
like image 92
Junaid Avatar answered Oct 27 '25 01:10

Junaid