
Stepped Line
From syxUI — written for both platforms, not translated between them.
A stepped line chart for tiered values.
Charts · SwiftUI · iOS 17
- charts
- swiftui
The actual source
StepLineChart.swift
// Stepped Line · syxUI · https://syxui.dev/components/chart2-step-line
// Free in any project. Keep this line and credit syxUI where a person can read it.
import SwiftUI
let chGreen = Color(red: 0.16, green: 0.66, blue: 0.40)
extension View {
func formaCard(_ pad: CGFloat = 18) -> some View {
self.padding(pad)
.background(Color(.systemBackground), in: RoundedRectangle(cornerRadius: 20, style: .continuous))
.overlay(RoundedRectangle(cornerRadius: 20, style: .continuous).stroke(Color.primary.opacity(0.06), lineWidth: 1))
.shadow(color: .black.opacity(0.05), radius: 14, x: 0, y: 6)
}
}
// Stepped line chart
struct StepLineChart: View {
let pts: [Double] = [0.3, 0.3, 0.6, 0.6, 0.45, 0.8, 0.8]
var body: some View {
VStack(alignment: .leading, spacing: 10) {
Text("Plan tier over time").font(.system(size: 15, weight: .semibold))
GeometryReader { g in
let w = g.size.width, h = g.size.height, st = w / CGFloat(pts.count - 1)
Path { p in
p.move(to: CGPoint(x: 0, y: h - CGFloat(pts[0]) * h))
for i in 1..<pts.count { p.addLine(to: CGPoint(x: CGFloat(i) * st, y: h - CGFloat(pts[i - 1]) * h)); p.addLine(to: CGPoint(x: CGFloat(i) * st, y: h - CGFloat(pts[i]) * h)) }
}.stroke(chGreen, style: StrokeStyle(lineWidth: 2.5, lineJoin: .round))
}.frame(height: 100)
}.formaCard().frame(width: 320)
}
}
iOS 17 · No dependencies
Dependencies
- SwiftUI
- No external dependencies
Requires iOS 17


