SweetUI

Search items

Jump to an item

recipe

chart-tooltip

chartXSelection + RuleMark annotation.

chart-tooltipchartselectionannotationguidance
chart-tooltip, light

On iPad

The same installed source at a regular width. It adapts its layout without a separate design.

chart-tooltip on iPad, light

Install

Usage

@State private var selectedMonth: String?

var selected: MonthlyBalance? {
    balances.first { $0.month == selectedMonth }
}

Chart {
    ForEach(balances) { row in
        BarMark(
            x: .value("Month", row.month),
            y: .value("Balance", row.amount)
        )
        .foregroundStyle(TintShapeStyle())
    }
    if let selected {
        RuleMark(x: .value("Month", selected.month))
            .foregroundStyle(.secondary)
            .annotation(position: .top) {
                Text(selected.amount, format: .currency(code: "KWD"))
                    .font(.footnote.monospacedDigit())
                    .padding(6)
                    .registrySurface()
            }
    }
}
.chartXSelection(value: $selectedMonth)
.registryChart()
.registryItem("chart-tooltip")

Why native is enough

chartXSelection binds mark's x type; tap/drag native. Adds RuleMark + top annotation on registry surface; only .registryChart() themes. Single-series needs explicit accent, else default color. Keep annotation short; type MUST match mark's x, or nothing selects.

Accessibility contract

  • Marks expose to VoiceOver via audio graph, value text.
  • Selected value: visible text, not color alone.

Details

Kindrecipe
Version0.1.1
PlatformsiOS 26.0+
Dependencieschart
Sourcenone (native guidance)