SP GlassKit1.1.0

GlassChart

Swift Charts line, bar and area charts with axes, units and accessible descriptions.

  • Content
  • iOS 26 · iPadOS 26 · macOS 26
  • Version 1.1.0
  • glass-chart

Content on an opaque, readable surface. Glass is kept for controls.

GlassChart running in SP Glass Studio.Capture
Capture of the component running in SP Glass Studio on the iOS 26.5 simulator. Liquid Glass is rendered by the system; this is an image, not a live preview.

Installation

spglass add glass-chart

Copies the sources and their dependencies into your project. Set up the CLI.

Swift
.package(url: "https://git.spboucher.ai/sp-glasskit.git", from: "1.1.0")

import SPGlassKit
Identifierglass-chart
ModuleSPGlassData
Kindcontent-component — Swift Charts on an opaque surface; glass only for the optional floating control
PlatformsiOS 26, iPadOS 26, macOS 26
FrameworksCharts
ExampleExamples/Gallery/Data/GlassChartExample.swift

Minimal usage

Swift
GlassChart("Monthly revenue", points: [
    GlassChartPoint(label: "Jan", value: 42),
    GlassChartPoint(label: "Feb", value: 48),
    GlassChartPoint(label: "Mar", value: 55),
])

Variants

VariantUse
kind: .lineEvolution of a value. Series are told apart by colour, by symbol and by the legend.
kind: .barComparison between categories.
kind: .areaVolume over time; several series are stacked by Swift Charts.
Category axisPoints created with label:.
Time axisUsed when every point is created with date:.
Several seriesPoints with a series name; a legend appears.
Overlay controlA trailing closure with a small control (series or range picker), drawn on a glass capsule over the top trailing corner of the plot.

Parameters

ParameterTypeDefaultMeaning
titleLocalizedStringKey—Heading and accessibility label of the chart.
points[GlassChartPoint]—Typed values. Non-finite values are skipped.
kindGlassChartKind.lineMark type.
xAxisTitleString?nilTitle of the horizontal axis, already localised.
yAxisTitleString?nilTitle of the vertical axis, already localised.
unitString?nilUnit, appended to the vertical axis title ("Energy (MWh)") and to spoken values.
showsSummaryBooltrueShows the generated description under the plot.
overlay@ViewBuildernoneControl floating on glass.

GlassChartPoint(id:label:value:series:) and GlassChartPoint(id:date:value:series:); without an id, one is derived from the series and the position.

Read-out and selection

ParameterTypeDefaultMeaning
selectionBinding<GlassChartX?>?nilThe selected horizontal position. Without a binding the chart keeps its own.

The header shows the title, the vertical axis title with its unit, and a read-out: the value of each series at the selected position, or at the last position when nothing is selected. Touching or dragging the plot selects a position (Swift Charts' own selection gesture, so scrolling keeps working) and draws a rule there. Gridlines are hairlines, axis labels use the theme's secondary text colour, lines are smoothed and carry point symbols, areas are a light fill under a line, bars have rounded corners and series sit side by side. The plot is between 180 and 260 points tall. GlassChartLogic.readout(of:at:) and nearestPosition(to:in:) are pure and public.

States

  • Empty (no finite value): the title and a ContentUnavailableView reading "No data".
  • Populated: the plot, the optional overlay control and the summary sentence.
  • Loading and failure are the host's responsibility (wrap the chart, or show a GlassMetricCard-style state around it).

Advanced example

Swift
@State private var series = "All"

var visible: [GlassChartPoint] {
    series == "All" ? production : production.filter { $0.series == series }
}

GlassChart("Energy produced", points: visible, kind: .area, xAxisTitle: "Month", yAxisTitle: "Energy", unit: "MWh") {
    Picker("Series", selection: $series) {
        Text("All").tag("All")
        ForEach(GlassChartLogic.seriesNames(production), id: \.self) { Text(verbatim: $0).tag($0) }
    }
    .pickerStyle(.menu)
}

// The description is a pure function, usable outside the view:
let text = GlassChartLogic.description(of: production, unit: "MWh")
// "North: 6 values from Jan to Jun. Minimum 42 MWh, maximum 70 MWh. Trend: Up. South: …"

Accessibility

  • Every mark has an accessibility label (series and position) and value (formatted number and unit), so the chart can be explored element by element and with the system's audio graph.
  • A sentence per series states the number of values, the first and last positions, the minimum, the maximum and the trend. It is visible under the plot, or kept as an accessibility-only element when showsSummary is false.
  • Series never rely on colour alone: the legend names them and line charts add a distinct symbol per series.
  • Numbers and dates are formatted with FormatStyle in the environment's locale and time zone.

Limits

  • The trend compares the last value with the first one; it is flat when they differ by at most 1 % of the series' scale. It is a description, not a regression.
  • The overlay control covers the top trailing corner of the plot; keep it small.
  • Series colours come from Swift Charts' default palette; a single series uses the theme's primary colour. Per-series theme colours are not exposed.
  • No selection, zooming or scrolling of the plot: use Swift Charts directly for interactive charts.
  • A chart mixing dated and labelled points uses a category axis, with dates shown as abbreviated text.
  • Rendering was compiled for macOS and iOS; the visual result was not checked on a device in this phase.

Example

Complete example (compiled with the package)
import SwiftUI
import SPGlassKit

public struct GlassChartExample: GlassExample {
    public static let componentID = "glass-chart"

    // Fictitious data: energy produced by two imaginary sites.
    private static let months = ["Jan", "Feb", "Mar", "Apr", "May", "Jun"]
    private static let north: [Double] = [42, 48, 55, 61, 58, 70]
    private static let south: [Double] = [65, 60, 57, 52, 49, 44]

    private static let production: [GlassChartPoint] =
        zip(months, north).map { GlassChartPoint(label: $0, value: $1, series: "North") }
        + zip(months, south).map { GlassChartPoint(label: $0, value: $1, series: "South") }

    private static let visits: [GlassChartPoint] = {
        let start = Date(timeIntervalSince1970: 1_780_272_000)
        let values: [Double] = [120, 135, 128, 160, 190, 240, 210]
        return values.enumerated().map { GlassChartPoint(date: start.addingTimeInterval(Double($0.offset) * 86_400), value: $0.element) }
    }()

    @State private var kind = GlassChartKind.line
    @State private var series = "All"

    public init() {}

    private var visibleProduction: [GlassChartPoint] {
        series == "All" ? Self.production : Self.production.filter { $0.series == series }
    }

    public var body: some View {
        ScrollView {
            VStack(spacing: 16) {
                Picker("Mark", selection: $kind) {
                    Text("Line").tag(GlassChartKind.line)
                    Text("Bar").tag(GlassChartKind.bar)
                    Text("Area").tag(GlassChartKind.area)
                }
                .pickerStyle(.segmented)

                GlassChart("Energy produced", points: visibleProduction, kind: kind, xAxisTitle: "Month", yAxisTitle: "Energy", unit: "MWh") {
                    Picker("Series", selection: $series) {
                        Text("All").tag("All")
                        ForEach(GlassChartLogic.seriesNames(Self.production), id: \.self) { Text(verbatim: $0).tag($0) }
                    }
                    .pickerStyle(.menu)
                }

                GlassChart("Daily visits", points: Self.visits, kind: .area, xAxisTitle: "Day", yAxisTitle: "Visits")

                GlassChart("Nothing measured yet", points: [])
            }
            .padding()
        }
    }
}

#Preview("GlassChart") { GlassChartExample().glassTheme(.ocean) }

Registry entry

Identifierglass-chart
Version1.1.0
Depends onglass-data-support, glass-foundation
FrameworksSwiftUI, Charts
Public symbolsGlassChart, GlassChartKind, GlassChartX, GlassChartPoint, GlassChartSummary, GlassChartReadout, GlassChartLogic
LicenceMIT
Manifestmanifest.json

Files