
Candlestick Chart
From syxUI — written for both platforms, not translated between them.
A hand-built candlestick chart — self-contained SwiftUI, no chart framework, restyles from one accent.
Charts · SwiftUI · iOS 17
- charts
- swiftui
The actual source
CardHeader.swift
// Candlestick Chart · syxUI · https://syxui.dev/components/chart-candles
// Free in any project. Keep this line and credit syxUI where a person can read it.
import SwiftUI
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)
}
}
struct CardHeader: View {
let label: String; let value: String; var trend: String? = nil
var body: some View {
HStack(alignment: .firstTextBaseline) {
VStack(alignment: .leading, spacing: 3) {
Text(label).font(.system(size: 13, weight: .medium)).foregroundStyle(.secondary)
Text(value).font(.system(size: 26, weight: .bold))
}
Spacer()
if let trend {
Text(trend).font(.system(size: 12, weight: .semibold))
.padding(.horizontal, 8).padding(.vertical, 3)
.background(Color.primary.opacity(0.06), in: Capsule())
}
}
}
}
// 8. Candlestick
struct CandlestickCard: View {
let candles: [(Double, Double, Double, Double)] = [
(0.4, 0.6, 0.35, 0.55), (0.55, 0.7, 0.5, 0.52), (0.52, 0.58, 0.4, 0.45),
(0.45, 0.5, 0.3, 0.48), (0.48, 0.72, 0.45, 0.68), (0.68, 0.8, 0.6, 0.62),
(0.62, 0.66, 0.5, 0.58), (0.58, 0.9, 0.55, 0.85)]
var body: some View {
VStack(alignment: .leading, spacing: 14) {
CardHeader(label: "AAPL", value: "$237.61", trend: "+1.07%")
GeometryReader { g in
let h = g.size.height
HStack(alignment: .bottom, spacing: 8) {
ForEach(candles.indices, id: \.self) { i in
let c = candles[i]; let up = c.3 >= c.0
ZStack {
Rectangle().fill(Color.primary.opacity(0.4)).frame(width: 1.5, height: h * (c.1 - c.2))
.offset(y: -h * (min(c.0, c.3) - c.2) + h * (max(c.0, c.3) - min(c.0, c.3)) / 2 - h * (c.1 - max(c.0, c.3)))
RoundedRectangle(cornerRadius: 1).fill(up ? Color.primary : Color.primary.opacity(0.28))
.frame(width: 7, height: max(3, h * abs(c.3 - c.0)))
}
.frame(maxHeight: .infinity, alignment: .bottom)
.offset(y: -h * min(c.0, c.3))
}
}
}
.frame(height: 90)
}
.formaCard()
}
}
iOS 17 · 2 dependencies
Dependencies
- SwiftUI
- formaCard
- CardHeader
Requires iOS 17


