Skip to main content

CandleChartStyle

Visual configuration for CandlestickChart. Defaults use semantic system colors, so the chart adapts to light mode, dark mode and increased contrast automatically. See the Styling guide for a friendlier walkthrough — this page is the terse full reference.

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
}

Initializer​

public init(
upColor: Color = .green,
downColor: Color = .red,
hollowUpCandles: Bool = false,
bodyWidthRatio: CGFloat = 0.7,
volumeOpacity: Double = 0.28,
gridColor: Color = Color.secondary.opacity(0.14),
axisLabelColor: Color = .secondary,
crosshairColor: Color = Color.primary.opacity(0.55),
indicatorPalette: [Color] = [.orange, .purple, .teal, .pink, .indigo, .brown],
priceAxisMaterial: Material? = nil,
crosshairDimOpacity: Double = 0.28
)

bodyWidthRatio is clamped to 0.1...1, and crosshairDimOpacity is clamped to 0...1.

Properties​

PropertyTypeDefaultDescription
upColorColor.greenFill color for bullish candles.
downColorColor.redFill color for bearish candles.
hollowUpCandlesBoolfalseDraws rising candles as outlines instead of filled bodies.
bodyWidthRatioCGFloat0.7Candle body width as a fraction of the slot width.
volumeOpacityDouble0.28Opacity of the volume bars.
gridColorColorColor.secondary.opacity(0.14)Background grid line color.
axisLabelColorColor.secondaryPrice/time axis tick label color.
crosshairColorColorColor.primary.opacity(0.55)Crosshair line/label color.
indicatorPalette[Color][.orange, .purple, .teal, .pink, .indigo, .brown]Colors that IndicatorColorRole.series(_:) cycles through.
priceAxisMaterialMaterial?nilnil keeps the classic transparent axis. A Material turns on a frosted axis with candles blurred behind it.
crosshairDimOpacityDouble0.28How much every non-focused candle dims while the crosshair is showing. 0 disables dulling.

Static presets​

public static var standard: CandleChartStyle { get } // CandleChartStyle()
public static var redUp: CandleChartStyle { get } // upColor: .red, downColor: .green
public static var colorBlindSafe: CandleChartStyle { get } // upColor: .blue, downColor: .orange
PresetupColordownColorUse case
.standard.green.redDefault — green for rising, red for falling.
.redUp.red.greenConvention in mainland China, Taiwan and South Korea.
.colorBlindSafe.blue.orangeStays distinguishable under the most common forms of color blindness.