
Spark Bars
From syxUI — written for both platforms, not translated between them.
A stat with a mini bar sparkline.
Charts · SwiftUI · iOS 17
- charts
- swiftui
The actual source
SparkBarsStat.swift
// Spark Bars · syxUI · https://syxui.dev/components/chart2-sparkbars
// Free in any project. Keep this line and credit syxUI where a person can read it.
import SwiftUI
let chBlue = Color(red: 0.0, green: 0.47, blue: 1.0)
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)
}
}
// Mini bar sparkline stat
struct SparkBarsStat: View {
let bars: [Double] = [0.4, 0.6, 0.5, 0.8, 0.65, 0.9, 0.7, 0.85, 0.6, 0.95]
var body: some View {
VStack(alignment: .leading, spacing: 10) {
HStack { Text("Weekly revenue").font(.system(size: 13)).foregroundStyle(.secondary); Spacer(); Text("+18%").font(.system(size: 12, weight: .semibold)).foregroundStyle(chGreen) }
Text("$4,820").font(.system(size: 24, weight: .bold))
HStack(alignment: .bottom, spacing: 4) {
ForEach(Array(bars.enumerated()), id: \.offset) { i, v in
RoundedRectangle(cornerRadius: 2).fill(i == bars.count - 1 ? chBlue : chBlue.opacity(0.2)).frame(height: CGFloat(40 * v))
}
}.frame(height: 40)
}.formaCard().frame(width: 280)
}
}
iOS 17 · No dependencies
Dependencies
- SwiftUI
- No external dependencies
Requires iOS 17


