Charts – Beautiful charts for iOS/tvOS/OSX
Okay so there’s this beautiful library called MPAndroidChart by Philipp Jahoda which has become very popular amongst Android developers, but there was no decent solution to create charts for iOS.
I’ve chosen to write it in
Swift as it can be highly optimized by the compiler, and can be used in both
ObjC project. The demo project is written in
ObjC to demonstrate how it works.
An amazing feature of this library now, for Android, iOS, tvOS and macOS, is the time it saves you when developing for both platforms, as the learning curve is singleton- it happens only once, and the code stays very similar so developers don’t have to go around and re-invent the app to produce the same output with a different library. (And that’s not even considering the fact that there’s not really another good choice out there currently…)
Having trouble running the demo?
ChartsDemo/ChartsDemo.xcodeprojis the demo project for iOS/tvOS
ChartsDemo-OSX/ChartsDemo-OSX.xcodeprojis the demo project for macOS
- Make sure you are running a supported version of Xcode.
- Usually it is specified here a few lines above.
- In most cases it will be the latest Xcode version.
- Make sure that your project supports Swift 5.0
- Optional: Run
carthage checkoutin the project folder, to fetch dependencies (i.e testing dependencies).
- If you don’t have Carthage – you can get it here.
In order to correctly compile:
- Drag the
Charts.xcodeprojto your project
- Go to your target’s settings, hit the “+” under the “Frameworks, Libraries, and Embedded Content” section, and select the Charts.framework
- When using Swift in an ObjC project:
- You need to import your Bridging Header. Usually it is “YourProject-Swift.h“, so in ChartsDemo it’s “ChartsDemo-Swift.h“. Do not try to actually include “ChartsDemo-Swift.h” in your project 🙂
- (Xcode 8.1 and earlier) Under “Build Options”, mark “Embedded Content Contains Swift Code”
- (Xcode 8.2+) Under “Build Options”, mark “Always Embed Swift Standard Libraries”
- When using Realm.io:
- Note that the Realm framework is not linked with Charts – it is only there for optional bindings. Which means that you need to have the framework in your project, and in a compatible version to whatever is compiled with Charts. We will do our best to always compile against the latest version.
- You’ll need to add
ChartsRealmas a dependency too.
3rd party tutorials
- Chart in Swift – Setting Up a Basic Line Chart Using iOS Charts(Alex Nagy)
- Charts Framework in SwiftUI – Bar Chart (Stewart Lynch)
- Using Realm and Charts with Swift 3 in iOS 10 (Sami Korpela)
- Creating a Line Chart in Swift 3 and iOS 10 (Osian Smith)
- Beginning Set-up and Example Using Charts with Swift 3
- Creating a Radar Chart in Swift (David Piper)
- Plotting in IOS using Charts framework with SwiftUI (Evgeny Basisty)
- Set Up a Basic Bar Chart Using iOS-Charts (Penny Huang)
- iOS-Charts Tutorial: Highlight Selected Value With a Custom Marker (Penny Huang)
Want your tutorial to show here? Create a PR!
- Please note the difference between installing a compiled framework from CocoaPods or Carthage, and copying the source code.
- Please read the Usage section again.
- Search in the issues
- Try to politely ask in the issues section
Other problems / feature requests
- Search in the issues
- Try to politely ask in the issues section
pod 'Charts' to your Podfile. “Charts” is the name of the library.
For Realm support, please add
pod 'ChartsRealm' too.
is not the correct library, and refers to a different project by someone else.
Charts now include Carthage prebuilt binaries.
github "danielgindi/Charts" == 4.1.0 github "danielgindi/Charts" ~> 4.1.0
In order to build the binaries for a new release, use
carthage build --no-skip-current && carthage archive Charts.
Swift Package Manager Install
Swift Package Manager
dependencies: [ .package(url: "https://github.com/danielgindi/Charts.git", .upToNextMajor(from: "4.1.0")) ]
3rd party bindings
Xamarin (by @Flash3001): iOS – GitHub/NuGet. Android – GitHub/NuGet.
If you like what you see here, and want to support the work being done in this repository, you could:
- Contribute code, issues and pull requests
- Let people know this library exists (🔥 spread the word 🔥)
- (You can buy me a beer, or you can buy me dinner 🙂
Note: The author of MPAndroidChart is the reason that this library exists, and is accepting donations on his page. He deserves them!
Questions & Issues
If you are having questions or problems, you should:
- Make sure you are using the latest version of the library. Check the release-section.
- Study the Android version’s Documentation-Wiki
- Search or open questions on stackoverflow with the
- Search known issues for your problem (open and closed)
- Create new issues (please 🔥 search known issues before 🔥, do not create duplicate issues)
- 8 different chart types
- Scaling on both axes (with touch-gesture, axes separately or pinch-zoom)
- Dragging / Panning (with touch-gesture)
- Combined-Charts (line-, bar-, scatter-, candle-stick-, bubble-)
- Dual (separate) Axes
- Customizable Axes (both x- and y-axis)
- Highlighting values (with customizable popup-views)
- Save chart to camera-roll / export to PNG/JPEG
- Predefined color templates
- Legends (generated automatically, customizable)
- Animations (build up animations, on both x- and y-axis)
- Limit lines (providing additional information, maximums, …)
- Fully customizable (paints, typefaces, legends, colors, background, gestures, dashed lines, …)
- Plotting data directly from Realm.io mobile database (here)
Screenshots are currently taken from the original repository, as they render exactly the same 🙂
BarChart (with legend, simple design)
- BarChart (grouped DataSets)
- PieChart (with selection, …)
- ScatterChart (with squares, triangles, circles, … and more)
- CandleStickChart (for financial data)
- BubbleChart (area covered by bubbles indicates the value)
- RadarChart (spider web chart)
Currently there’s no need for documentation for the iOS/tvOS/macOS version, as the API is 95% the same as on Android.
You can read the official MPAndroidChart documentation here: Wiki
Or you can see the Charts Demo project in both Objective-C and Swift (ChartsDemo-iOS, as well as macOS ChartsDemo-macOS) and learn the how-tos from it.
Mobile App Development Best Practices – 06.06
iOS SwiftUI Testing: a Pragmatic Approach Enhancing Security in iOS Applications: Best Practices and Code Examples Beautify Code Without Optionals...
Apple announces Vision Pro augmented reality headset
The Vision Pro is marketed primarily as an AR device, but it can switch between augmented and full virtual reality...
WWDC 2023 Keynote
Check out the WWDC23 keynote, where the latest Apple Vision Pro, MacBook Air 15″, software, services and operating systems were...
LeetCode by Swift – Solutions to LeetCode by Swift
LeetCode Online Judge is a website containing many algorithm questions. Most of them are real interview questions of Google, Facebook, LinkedIn, Apple, etc....
Mobile App Development Best Practices – 05.06
iOS Using Upcoming Feature Flags Network Path Monitoring What’s new in Swift 5.9? Building a robust clean architecture/VIPER iOS app...
Create a game with libGDX
In this exciting episode of our show, we dive into the thrilling world of game development with our guest, Daniele...