+1
Daily
5,648
stars
634
forks
94
watchers
104
prs
158
issues
23
releases
README
SwiftUICharts
SwiftUICharts is a composable, SwiftUI-native chart library for iOS 13+.
2.0.0 is a major release focused on immutable configuration, environment-driven composition, and modifier-based APIs.
AI Agent Quick Context
Use this section when an AI agent generates code against this package.
API contract
- Use only 2.x composable APIs.
- Do not use legacy 1.x types or mutating chains.
- Build charts with ViewModifier composition.
- Keep data source semantics explicit:
- chartData([Double]) = categorical slots
- chartData([(Double, Double)]) = numeric/continuous domain
Use these APIs
| Task | API |
| --- | --- |
| Set data | chartData(...) |
| Set ranges | chartXRange(...), chartYRange(...) |
| Style chart | chartStyle(...) |
| Grid config | chartGridLines, chartGridStroke, chartGridBaseline |
| Axis labels/ticks | chartXAxisLabels, chartYAxisLabels, chartXAxisAutoTicks, chartYAxisAutoTicks |
| Line tuning | chartLineWidth, chartLineStyle, chartLineMarks, chartLineAnimation |
| Shared interaction | chartInteractionValue(...) |
| Callback interaction | chartSelectionHandler { event in ... } |
| Streaming data | ChartStreamingDataSource + chartData(stream) |
| Large datasets | chartPerformance(...) |
Avoid these legacy APIs
- LineChartView, BarChartView, PieChartView, MultiLineChartView
- .data(...), .rangeX(...), .rangeY(...)
- .setAxisXLabels(...), .setNumberOfHorizontalLines(...)
- .showChartMarks(...) (old form)
Installation
Add with Swift Package Manager:
https://github.com/AppPear/ChartView
For this release, use tag 2.0.0 (or from: "2.0.0" up to next major).
30-Second Quick Start
swift
import SwiftUI
import SwiftUICharts
struct DemoView: View {
var body: some View {
AxisLabels {
ChartGrid {
LineChart()
.chartData([12, 34, 23, 18, 36, 22, 26])
.chartYRange(10...40)
.chartLineMarks(true, color: ColorGradient(.blue, .purple))
.chartStyle(
ChartStyle(
backgroundColor: .white,
foregroundColor: ColorGradient(.blue, .purple)
)
)
}
.chartGridLines(horizontal: 5, vertical: 6)
}
.chartXAxisLabels(["M", "T", "W", "T", "F", "S", "S"])
.chartAxisColor(.secondary)
.chartAxisFont(.caption)
.frame(height: 220)
.padding()
}
}
Feature Recipes
1) Mixed bar + line
swift
AxisLabels {
ChartGrid {
BarChart()
.chartData([2, 4, 1, 3, 5])
.chartStyle(ChartStyle(backgroundColor: .white,
foregroundColor: ColorGradient(.orange, .red)))
LineChart()
.chartData([2, 4, 1, 3, 5])
.chartLineMarks(true)
.chartStyle(ChartStyle(backgroundColor: .white,
foregroundColor: ColorTop issues
#56LineView not properly scaling with large values19 comments · 2020-03-06#124Broken GitHub actions 9 comments · 2020-06-27#243Can't get legend or x and y labels8 comments · 2022-06-02#79Add new chart size7 comments · 2020-05-13#217Label using UI Color it stop working in macOS6 comments · 2021-10-11#14Multiple lines6 comments · 2019-11-03#220Package resolution failed?5 comments · 2021-11-06#212Is this possible now?5 comments · 2021-09-21
Discussions
#268Any chance for this repo to be revived?0 comments · 2024-06-28#261Large data set and cpu 100%?0 comments · 2023-06-05#258Piecharts interactive?0 comments · 2023-01-19#242Problems faced in LineView in release version0 comments · 2022-04-16#240Data for LineView shown without .00, no Double0 comments · 2022-04-07#225how can I render it as in Readme.md0 comments · 2021-11-24#223@ObservableObject instead of @EnvironmentObject to init charts?1 comments · 2021-11-23#216Could not find module 'SwiftUICharts' for target 'x86_64-apple-ios-simulator'; found: arm64, arm64-apple-ios-simulator2 comments · 2021-10-01
Latest release
2.0.0 2.0.0 2026-03-02Changelog 2.0.0 Added - Full SwiftUI-idiomatic modifier API: - chartData, chartXRange, chartYRange - chartGridLines, chartGridStroke, chartGridBaseline - chartXAxisLabels, chartYAxisLabels, chartAxisFont, chartAxisColor - chartLineWidth, chartLineBackground, chartLineMarks, chartLineStyle, chartLineAnimation - chartInteractionValue - chartSelectionHandler - chartPerformance - Immutable chart configuration structs and environment-key-based composition. - Updated docs/examples and generated showcase app. - Dynamic streaming data source support via ChartStreamingDataSource. - U