Skip to main content

Styling

Everything about how a chart looks — candle colors, grid, axis labels, the crosshair, and the palette indicators cycle through — lives in one CandleChartStyle value, attached with .candleChartStyle(_:). Its defaults use semantic system colors, so an unstyled chart already adapts correctly to light mode, dark mode and increased contrast without you doing anything.

CandlestickChart(candles)
.candleChartStyle(.standard)

Every property​

public struct CandleChartStyle {
public var upColor: Color
public var downColor: Color
public var hollowUpCandles: Bool
public var bodyWidthRatio: CGFloat
public var volumeOpacity: Double
public var gridColor: Color
public var axisLabelColor: Color
public var crosshairColor: Color
public var indicatorPalette: [Color]
public var priceAxisMaterial: Material?
public var crosshairDimOpacity: Double
}
PropertyWhat it controls
upColor / downColorThe fill color for bullish (close ≥ open) and bearish candles.
hollowUpCandlesDraws rising candles as outlines instead of filled bodies.
bodyWidthRatioCandle body width as a fraction of its slot width (clamped to 0.1...1).
volumeOpacityOpacity of the volume bars underneath the candles.
gridColorColor of the background grid lines.
axisLabelColorColor of the price/time axis tick labels.
crosshairColorColor of the crosshair line and its floating labels.
indicatorPaletteColors that IndicatorColorRole.series(_:) cycles through, so two overlays added back to back get visually distinct colors automatically.
priceAxisMaterialnil keeps the classic fully-transparent axis. Set a Material (e.g. .ultraThinMaterial) to turn on a frosted price axis, with candles softly blurred behind it as they scroll toward the edge.
crosshairDimOpacityHow much every candle other than the focused one dims while the crosshair is showing (0 disables dulling entirely).

All parameters have defaults, so you only need to specify the ones you're actually changing:

CandlestickChart(candles)
.candleChartStyle(CandleChartStyle(
priceAxisMaterial: .ultraThinMaterial,
bodyWidthRatio: 0.6
))

Built-in presets​

CandleKit ships three ready-made styles as static properties on CandleChartStyle:

PresetWhat it's for
.standardGreen for rising candles, red for falling — the convention most Western traders expect. This is the default if you don't set a style at all.
.redUpRed for rising, green for falling — the convention used in mainland China, Taiwan and South Korea.
.colorBlindSafeBlue and orange, chosen to stay distinguishable under the most common forms of color blindness.
CandlestickChart(candles)
.candleChartStyle(.redUp)

A custom style​

Since CandleChartStyle is a plain struct with memberwise defaults, building your own house style is just constructing one with the properties you care about:

extension CandleChartStyle {
static var midnight: CandleChartStyle {
CandleChartStyle(
upColor: .mint,
downColor: .pink,
hollowUpCandles: true,
bodyWidthRatio: 0.65,
volumeOpacity: 0.2,
indicatorPalette: [.yellow, .cyan, .purple],
priceAxisMaterial: .ultraThinMaterial
)
}
}

CandlestickChart(candles)
.candleChartStyle(.midnight)

See the style API reference for the full initializer signature and every default value.