ChartKit is a Swift Package of reusable SwiftUI chart examples and Apple Health-inspired chart components built on Apple Swift Charts. The repository also includes a small demo app that consumes the package and renders every chart with sample data.
The current package has two purposes:
- Provide a catalog of reusable Swift Charts implementations.
- Provide fixture-backed Apple Health and Clinical Health Record chart families that another app can embed before wiring in HealthKit or FHIR data adapters.
- Xcode 15 or newer
- Swift 5.9 or newer
- iOS 16 or newer
- macOS 13 or newer
- SwiftUI
- Charts
The package does not request HealthKit authorization. Health and Clinical charts currently render from normalized fixture models so the visual components can be inspected and integrated independently of HealthKit permissions.
Package.swift
Sources/ChartKit/
Charts/ Existing Swift Charts examples
Data/ Sample data used by the original chart examples
HealthCharts/ Apple Health and Clinical Health Record chart models, fixtures, and views
Model/ Demo catalog registration
Utilities/ Shared platform and accessibility helpers
ChartKitDemo/ Demo app shell
ChartKitDemoTests/
The Xcode app target is intentionally thin. It imports ChartKit and launches ChartGalleryView.
In Xcode:
- Open your app project.
- Choose
File > Add Package Dependencies.... - Add this repository URL:
git@github.com:advatar/ChartKit.git
- Select the
ChartKitpackage product. - Import the package where you want to render charts:
import ChartKitFor a local package during development, add this repository folder as a local package dependency and select the ChartKit product.
// Package.swift
dependencies: [
.package(url: "git@github.com:advatar/ChartKit.git", branch: "main")
],
targets: [
.target(
name: "YourApp",
dependencies: [
.product(name: "ChartKit", package: "ChartKit")
]
)
]Render the complete gallery:
import ChartKit
import SwiftUI
struct ChartsScreen: View {
var body: some View {
ChartGalleryView()
}
}This is the currently public package entry point. The individual chart examples are still mostly internal to the package while the API is being shaped. For now, consume ChartGalleryView directly or use the source as implementation references.
For apps that need an individual clinical chart now, ChartKit exposes a narrow clinical trend API:
ClinicalMetricTrendChartClinicalMetricSparklineChartClinicalTrendChartPointClinicalTrendReferenceBandClinicalTrendXAxisLabelStyle
Map your app's clinical observations into ClinicalTrendChartPoint, keep selection state in the consuming app, and pass bindings into the chart:
import ChartKit
import SwiftUI
struct HemoglobinTrend: View {
@State private var selectedDate: Date?
@State private var scrollPosition = Date()
let points: [ClinicalTrendChartPoint]
var body: some View {
ClinicalMetricTrendChart(
points: points,
selectedPoint: points.last,
referenceBand: ClinicalTrendReferenceBand(low: 13.5, high: 17.5),
visibleDomainLength: 180 * 24 * 60 * 60,
usesYearAxisLabels: false,
axisLabelStyle: .month,
accentColor: .green,
selectedDate: $selectedDate,
scrollPosition: $scrollPosition
)
}
}ClinicalMetricTrendChart requires iOS 17 or macOS 14 because it uses Swift Charts selection and scroll APIs. ClinicalMetricSparklineChart is available anywhere the package can build.
To inspect the charts visually, run the included demo app:
open "ChartKit.xcodeproj"Then select the ChartKitDemo scheme and run it.
Command-line build:
xcodebuild \
-scheme 'ChartKitDemo' \
-project 'ChartKit.xcodeproj' \
-destination 'platform=macOS' \
build \
CODE_SIGNING_ALLOWED=NOThe demo sidebar includes these sample sections:
applelinebararearangeheatMappointhealthclinical
Health chart code lives in Sources/ChartKit/HealthCharts.
- Quantity timeline: cumulative bars for metrics such as Steps.
- Quantity range timeline: min/average/max rendering for metrics such as Heart Rate.
- Classification band chart: Cardio Fitness-style trend with background bands.
- Typical range chart: Vitals-style overnight metric plotted against a normal range.
- Sleep stages chart: hypnogram with Awake, REM, Core, and Deep intervals.
- Cycle Tracking timeline: day-based timeline for period prediction, fertile window, likely ovulation, logged period, and logged info.
- Medication and event timeline: scheduled/taken/skipped/detected/resolved events.
- Workout detail charts: heart rate, pace, and elevation examples.
The Health chart components use normalized models rather than direct HealthKit types:
HealthQuantityBucketHealthRangeBandSleepStageSegmentCycleTrackingDayHealthEventWorkoutMetricPoint
This keeps rendering independent from HealthKit authorization and query mechanics. A production app should query HealthKit, aggregate or normalize the samples, then feed equivalent values into these chart models.
Typical HealthKit mapping:
- Cumulative quantity samples, such as steps, map to
HealthQuantityBucket.value. - Discrete metrics, such as heart rate, can map average/min/max values into
HealthQuantityBucket.value,minimum, andmaximum. - Sleep analysis category samples map to
SleepStageSegment. - Category samples and app-level state map to
HealthEvent. HKWorkoutplus associated samples map toWorkoutMetricPointor a future richer workout series model.
Clinical Health Record support is also in Sources/ChartKit/HealthCharts.
Clinical records are not normal HKQuantitySample values. HealthKit exposes them as read-only HKClinicalRecord samples containing FHIR-backed data. ChartKit models those records separately so clinical observations are not accidentally merged with user-tracked HealthKit samples.
- Clinical lab result trend chart.
- Clinical vital sign trend chart.
- Dedicated blood pressure chart for paired systolic/diastolic observations.
- Clinical timeline for immunizations, medications, conditions, procedures, and allergies.
- Clinical notes and coverage views.
Current normalized clinical models:
ClinicalObservationPointClinicalBloodPressureReadingClinicalTimelineRecord
Suggested FHIR mapping:
- FHIR
Observation.valueQuantitymaps toClinicalObservationPoint.valueandunit. - FHIR
Observation.referenceRangemaps to future range bands or threshold metadata. - FHIR
Observation.interpretationmaps to abnormal/high/low visual state. - Component-based blood pressure observations map systolic and diastolic components into
ClinicalBloodPressureReading. - FHIR
Immunization,MedicationRequest/MedicationStatement,Condition,Procedure,AllergyIntolerance,DocumentReference, andCoveragemap to timeline/card records.
Sample Health and Clinical data is in:
Sources/ChartKit/HealthCharts/HealthChartFixtures.swift
The fixtures are intentionally realistic enough to inspect layout and interaction states, but they are not intended to be medically accurate reference datasets.
The package is in an early refactor state.
ChartGalleryViewis public and intended for demo/gallery embedding.ClinicalMetricTrendChartandClinicalMetricSparklineChartare public for app-level clinical observation charts.- Most individual chart components and model types are internal today.
- The Health and Clinical chart views are fixture-backed first-pass implementations.
- Public per-chart APIs should be stabilized once the HealthKit/FHIR adapter layer is designed.
If another app needs to consume an individual chart immediately, promote the specific view and model types to public in a narrow follow-up change rather than making the entire package surface public at once.
Build the package:
swift buildBuild the demo app:
xcodebuild \
-scheme 'ChartKitDemo' \
-project 'ChartKit.xcodeproj' \
-destination 'platform=macOS' \
build \
CODE_SIGNING_ALLOWED=NOBuild the test bundle:
xcodebuild \
-scheme 'ChartKitDemo' \
-project 'ChartKit.xcodeproj' \
-destination 'platform=macOS' \
build-for-testing \
CODE_SIGNING_ALLOWED=NO- Add the chart view under
Sources/ChartKit/ChartsorSources/ChartKit/HealthCharts. - Add or reuse a normalized fixture/data model.
- Register the chart in
Sources/ChartKit/Model/ChartType.swift. - Confirm it appears in
ChartGalleryView. - Build with
swift build. - Build the demo app with
xcodebuild.
For charts intended for app reuse, prefer a small normalized model over taking direct framework types in the view initializer. This keeps the rendering layer testable and lets apps provide data from HealthKit, FHIR, JSON fixtures, or mock data.
Many of the original charts include accessibility descriptors or mark-level accessibility labels. The Health and Clinical chart implementations need additional pass-by-pass accessibility hardening as the visual designs stabilize.
Expected accessibility behavior:
- Announce selected value, unit, date, and source.
- Summarize visible range and trend.
- Describe threshold bands and abnormal values semantically.
- Represent sleep stage duration totals.
- Preserve clinical source/institution context where available.
The GitHub issues in this repository track the Health and Clinical chart implementation plan. The main areas are:
- Health quantity and range chart parity.
- Sleep stages parity.
- Cycle, medications, events, and workouts.
- HealthKit data normalization.
- Clinical lab/vital observations.
- Clinical blood pressure.
- Clinical record timelines.
- Screenshot catalog and visual QA against Apple Health references.
The package still includes the original chart examples as implementation references.
Electrocardiograms (ECG)
iPhone Storage
Screen Time
Line Chart
Line Chart with Lollipop
Animating Line
Line with changing gradient
Line Charts
Line Point
Single Bar
Single Bar with Threshold Rule Mark
Two Bars
Pyramid
Time Sheet Bar
Sound Bar
Horizontal Scrolling Bar Chart
Area Chart
Stacked Area Chart
Range Chart
Heart Rate Range Chart
Candle Stick Chart
Customizable Heat Map
GitHub Contributions Graph
Scatter Chart
Vector Field
Open Source - MIT License. See LICENSE.
























