Swiftpack.co - Package - danielgindi/Charts

Version 3.5.0, synced to MPAndroidChart #f6a398b

alt tag Supported Platforms Releases Latest pod release Carthage compatible Build Status codecov Join the chat at https://gitter.im/danielgindi/Charts

Just a heads up: Charts 3.0 has some breaking changes. Please read the release/migration notes.

Another heads up: ChartsRealm is now in a separate repo. Pods is also now Charts and ChartsRealm, instead of ~Charts/Core~ and ~Charts/Realm~

One more heads up: As Swift evolves, if you are not using the latest Swift compiler, you shouldn't check out the master branch. Instead, you should go to the release page and pick up whatever suits you.

  • Xcode 11 / Swift 5 (master branch)
  • iOS >= 8.0 (Use as an Embedded Framework)
  • tvOS >= 9.0
  • macOS >= 10.11

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 Swift and 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.xcodeproj is the demo project for iOS/tvOS
  • ChartsDemo-OSX/ChartsDemo-OSX.xcodeproj is 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 checkout in the project folder, to fetch dependencies (i.e testing dependencies).
    • If you don't have Carthage - you can get it here.

Usage

In order to correctly compile:

  1. Drag the Charts.xcodeproj to your project
  2. Go to your target's settings, hit the "+" under the "Embedded Binaries" section, and select the Charts.framework
  3. @import Charts
  4. 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"
  1. 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 ChartsRealm as a dependency too.

3rd party tutorials

Video tutorials

Blog posts

Want your tutorial to show here? Create a PR!

Troubleshooting

Can't compile?

  • 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

CocoaPods Install

Add pod 'Charts' to your Podfile. "Charts" is the name of the library.
For Realm support, please add pod 'ChartsRealm' too.

Note: ~~pod 'ios-charts'~~ is not the correct library, and refers to a different project by someone else.

Carthage Install

Charts now include Carthage prebuilt binaries.

github "danielgindi/Charts" == 3.5.0
github "danielgindi/Charts" ~> 3.5.0

In order to build the binaries for a new release, use carthage build --no-skip-current && carthage archive Charts.

3rd party bindings

Xamarin (by @Flash3001): iOS - GitHub/NuGet. Android - GitHub/NuGet.

Help

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 (:fire: spread the word :fire:)
  • Donate (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
  • Study the (Still incomplete Doc-Percent) Pod-Documentation
  • Search or open questions on stackoverflow with the ios-charts tag
  • Search known issues for your problem (open and closed)
  • Create new issues (please :fire: search known issues before :fire:, do not create duplicate issues)

Features

Core features:

  • 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)

Chart types:

Screenshots are currently taken from the original repository, as they render exactly the same :-)

  • LineChart (with legend, simple design) alt tag

  • LineChart (with legend, simple design) alt tag

  • LineChart (cubic lines) alt tag

  • LineChart (gradient fill) alt tag

  • Combined-Chart (bar- and linechart in this case) alt tag

  • BarChart (with legend, simple design)

alt tag

  • BarChart (grouped DataSets)

alt tag

  • Horizontal-BarChart

alt tag

  • PieChart (with selection, ...)

alt tag

  • ScatterChart (with squares, triangles, circles, ... and more)

alt tag

  • CandleStickChart (for financial data)

alt tag

  • BubbleChart (area covered by bubbles indicates the value)

alt tag

  • RadarChart (spider web chart)

alt tag

Documentation

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.

Special Thanks

Goes to @liuxuan30, @petester42 and @AlBirdie for new features, bugfixes, and lots and lots of involvement in our open-sourced community! You guys are a huge help to all of those coming here with questions and issues, and I couldn't respond to all of those without you.

Our amazing sponsors

Debricked: Use open source securely

debricked

License

Copyright 2016 Daniel Cohen Gindi & Philipp Jahoda

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Github

link
Stars: 23429

Dependencies

Used By

Total: 1

Releases

Xcode 12 support - 2020-09-21 07:27:47

Xcode 12 support

v3.5.0 Release - 2020-04-16 10:40:03

Build on Xcode 11.4 and latest Swift (pod)

Change log:https://github.com/danielgindi/Charts/blob/master/CHANGELOG.md

Merged pull requests: Full github commit log

3.4.0 Release - 2019-10-09 03:25:29

Support Xcode 11 and new Swift 5

Bug Fix

#4029: Index out of bounds exception in v3.2 in createAccessibleElement #4094: Horizontal Bezier Line Graph Not Drawing Through All Points #4093: Line chart x axis animation is broken #4099: Line renderer did not render lines if their coordinates fell outside of the viewport full change log:https://github.com/danielgindi/Charts/blob/master/CHANGELOG.md

pod updated

3.3.0 Release - 2019-04-24 02:52:22

This will be a breaking update due to #3847 that we changed dataSet initializers API interface and fixed Xcode warnings for previous release.

pod has been updated again to 3.3.0 tag, it's previously using 3.3

Now supports Xcode 10.2 and Swift 5.0

Highlights of fixed issues and merged requests:

Full change log

https://github.com/danielgindi/Charts/blob/master/CHANGELOG.md

3.2.2 Release - 2019-02-13 01:41:21

Highlights:

Implemented enhancements:

  • Multiple colors for valueline (Fixes #3480) #3709 (AlexeiGitH)
    • use useValueColorForLine to enable the same colors
  • Add Collection conformances to ChartDataSet types #3815 (jjatie)
  • improvements in barRect height calculation #3650 (potato04)

Fixed bugs:

  • CombinedChartView's candleData don't display in v3.2.0 #3662
  • Incorrect behavior for AxisBase.axisMaxLabels #3656
  • Horizontal Bar Chart legend issue #3301
  • Fixes sharp edges on the line chart #3764 (stokatyan)
  • Fix wrong assignment to axisMaxLabels property #3721 (ggirotto)
  • Fix legend offset bug for horizontal bar chart (Fixes #3301) #3736 (SvenMuc)
  • Add missing properties to copy(with:) methods #3715 (dstranz)
  • Fix applying lineCap value for line chart data sets (Fixes #3739) #3740 (anton-filimonov)
  • Fix memory leak after rendering #3680 (YusukeOba)
  • Fix condition that is checked before chartTranslated delegate method call #3804 (anton-filimonov)

Other merged pull requests:

Full changelog: https://github.com/danielgindi/Charts/blob/master/CHANGELOG.md

3.2.1 - 2018-10-08 19:58:24

  • Addresses crashes due to out of bounds exception when using stack bar charts
  • Updates podspec to use new swift version property

3.2.0 - 2018-09-17 01:41:17

Support for Swift 4.2 and Xcode 10.

Bug fixes and other improvements.

Don't use if you are NOT using Swift 4.2

3.1.1 Release - 2018-04-02 08:14:06

Support Xcode 9.3 and Swift 4.1 change log

3.1 Release - 2018-03-22 01:35:38

3.1 Release

(including pod)

  1. Refactored some components to better align with latest Swift language trend by jjatie.
  2. For bug and PRs, please check changelog, or https://github.com/danielgindi/Charts/projects/6
  3. New unit tests for pie chart.
  4. Support Xcode 9.2 and Swift 4.0.3

We are making Swift refactoring recently and target for 4.0 release along with some other features, thanks everyone for improving this project!

3.0.5 Release - 2018-01-08 02:21:55

Refactoring and New

  1. Refactored some components to better align with latest Swift language trend by jjatie.
  2. Add a new DataApproximator+N #2848 by 666tos.
  3. New unit tests for CombinedChartView and demo builds checker.

We are making Swift refactoring recently and target for 4.0 release along with some other features, thanks everyone for improving this project!

Bug fixes

to name a few that may impact users, others please refer change log:

  1. #2257 HorizontalBarChart does not update labels correctly
  2. #3132 Fix axis label disappear when zooming in deep enough
  3. #3149 Subclassing of LegendRenderer didn't take any effect
  4. #2049 fix the issue with axis dependencies in CombinedChartView
  5. Fix some Swift 4.0.3 errors to support Xcode 9.2

Swift 4 support - 2017-09-21 03:31:41

Add Swift 4 support

Xcode 9 and Swift 3.2 support - 2017-09-08 02:02:35

  • Adds Xcode 9 support
  • Adds Swift 3.2 support
  • Bug fixes and improvements

Minor improvements, icons supports, Swift 3.1 - 2017-04-03 04:27:20

  • Latest improvements / bugfixes
  • Icons support for most chart types
  • Updated to Swift 3.1

Stability Improvements - 2016-11-20 09:49:59

  1. This release improves stability and fixes bugs.
  2. Added a new IndexAxisValueFormatter that you can pass an array of labels and have them behave like in Charts 2.0

Bug Fixes and Improvements! - 2016-11-04 04:13:33

Disclaimer: This is a legacy release to support Swift 2.3 for Charts v2.2.5. You are encouraged to move to Swift 3.0 and Charts 3.0

Updates:

  • NSTouch extension for locationInView made the compiler error because it clashes with objc selector. Since it was not used in the library code it was removed.
  • Fix the image type of NSUIImagePNGRepresentation to be png instead of jpeg

Bridging the gap - 2016-09-21 02:13:53

Disclaimer: This is a legacy release to support Swift 2.3 for Charts v2.2.5. If you need Swift 3.0 support please wait for Charts v3.0.0 to be released

Updates:

  • We've moved to Swift 2.3, which means that the minimum required Xcode version is now 8.0

New major release - 2016-10-19 15:56:20

This is a major release, with a few breaking changes. So please pay attention.

Updates:

  • x-indexes are dead. Intoducing: x-values. Each entry now has an x and a y.
  • Pie/radar charts do not have a concept of X index anymore
  • Unified XAxis/YAxis features and experience.
  • Unified formatter interfaces for axes.
  • New formatter for y values, not inheriting from NSNumberFormatter anymore, to have dataSet and viewport information to take better formatting decisions.
  • Major refactoring of the Highlight mechanism.
  • Refactored marker mechanism
  • Refactored legend entry mechanism
  • Each dataset can now set its own legend form/size/etc.
  • More demos
  • Some classes have been renamed, keeping the namespaced name only in ObjC (using Swift 2.2 objc(...) feature, and the change of a major version update)
  • FillFormatter now has a block representation using FillFormatter.withblock(...)
  • Same goes for all Default formatters too.
  • No more saveToCameraRoll(). Since Xcode 8.0 it causes "privacy" issues with Apple Review, you have to add the photo albums privacy key to your Info.plist for that.
  • Moved to Swift 3.0. Make sure your project conforms to Swift 3.0.
  • Many minor bug fixes and improvements

Breaking changes / how to migrate:

  • All dataset constructors have changed - they do not take an array of x-indices anymore.
  • All entry constructors have changed - they take in an X and a Y.
  • Pie and Radar chart entries now have their own classes. So exchange the Entry classes withPieChartDataEntry/RadarChartDataEntry
  • If you have any old startAtZeroEnabled calls - these have been deprecated for a long time. Replace them with axisMinimum.
  • If you are using formatters:
    • Replace any chart.valueFormatter = formatter with chart.valueFormatter = ChartDefaultValueFormatter(formatter: formatter) or chart.valueFormatter = [[ChartDefaultValueFormatter alloc] initWithFormatter:formatter];
    • Replace any axis.valueFormatter = formatter with axis.valueFormatter = ChartDefaultAxisValueFormatter(formatter: formatter) or axis.valueFormatter = [[ChartDefaultAxisValueFormatter alloc] initWithFormatter:formatter];
  • In general, all functions that accepted x-indices before, now accept an x-value, so you might have to adjust the names a little bit.
  • Where ChartViewDelegate is implemented, update the chartValueSelected interface
  • Replace drawSliceTextEnabled with drawEntryLabelsEnabled
  • If you have a custom scatter shape - implement an IShapeRenderer, and put your rendering code in there
  • If you have a custom marker - consider subclassing MarkerView/MarkerImage or implementing IMarker. There are more options than before now...
  • If you have used barSpace before, move to using barWidth
  • If you used saveToCameraRoll(), replace with UIImageWriteToSavedPhotosAlbum(chart.getChartImage(trasparent: false), nil, nil, nil)
  • Some classes have been renamed for a cleaner look. They do not contain the "Chart" prefix anymore. That's for Swift only, where there are namespaces. In ObjC the names stayed the same for the sake of namespacing, using Swift 2.2's feature of @objc(name). If your compiler yells that a class does not exist, try to remove the Chart from its name. This should rarely happen, as we've chosen only the classes that are rarely instantiated by the user.

New features and bugfixes - The New-Born Release - 2016-05-30 06:49:22

  • New: Horizontal cubic bezier lines for Line chart (through mode property)
  • New: Allow transparent color in circle hole color (Line chart)
  • New: circleHoleRadius property for more control over line chart circles
  • New: PieChart values outside of chart (connected with lines)
  • New: highlightFullBar for highlighting all values on an x-index at once
  • New: Allow setting xVals on existing Data objects
  • New: Allow bubble sizes to not be normalized against the dataset max
  • New: Added material color template
  • New: Flag to control whether we draw a limit line's labels
  • New: Exploded the Legend-Position enum to support more combinations
  • New: Allow drawing borders for bars in a Bar chart
  • Improved: Highlighting when multiple values on x-index present (bubble chart, combined chart)
  • Fixed: We are now taking into account the extra offsets for Pie/Radar chart view
  • Fixes regarding MarkerView
  • Fixes regarding the transition to Swift 2.2
  • Improvements to Demo, now keeping dataset styling when changin dataset size
  • General bugfixes

Why newborn release? Because I have an amazing new baby girl!

New features, Swift 2.2/3.0, and bugfixes - 2016-03-31 20:50:53

  • Breaking change: Simplified setting axis min and max value. Now instead of 4 different confusing variables for axis min/max, there's only one to mess with: axisMinValue and axisMaxValue. These are instead of customAxisMin/customAxisMax. And axisMinimum/axisMaximum do not exist anymore. (This change happened on the Android side too, and is mutually compatible)
  • We've moved to Swift 2.2, which means that the minimum required Xcode version is now 7.3
  • New support for stepped line charts!
  • The new zero-line feature now defaults to false
  • Fixes related to cubic-lines
  • Improvements to edge cases in Pie charts
  • Many more bugfixes

New animations, OSX support, and more... - 2016-02-29 06:38:45

  • OSX support! (Thanks goes to @pixelspark)
  • Viewport can now me moved with animations
  • New candlestick rendering mode - without the bars, just lines and ticks
  • New X shape for scatter chart
  • PieChart improvements (slice spacing and other stuff)
  • CandleStickChart improvements
  • BubbleChart improvements
  • RadarChart improvements
  • ScatterChart improvements
  • General improvements and bugfixes

ChartsRealm is a separate framework now, color per value - 2016-02-09 08:14:13

  • ChartsRealm is a separate framework now (to avoid dependency problems)
  • Add support for setting different colors for values
  • Other minor fixes

Easier compilation when not referencing Realm - 2016-02-01 15:42:14

  • Updates podspec to include Realm support
  • Easier compilation of source code when not referencing Realm

Realm.io support, New features, Bugfixes - 2016-01-26 18:17:01

  • Plotting data directly from Realm.io mobile data base
  • Realm.io tutorial
  • Introducing DataSet interfaces (e.g. ILineDataSet), allowing you to implement other sources for datasets, which could possibly be dynamic.
  • Made all renderer members public for extensibility, due to lack of protected in Swift
  • Many bugfixes and little improvements

Note: This release may contain breaking changes for you if you have subclassed datasets/renderers.

New features, general improvements - 2015-11-02 21:17:54

  • Feature: XAxis labels can now be rotated
  • Feature: Disable tap-highlighting separately from highlighting via drag or programmatically
  • Feature: Support for customizing description text position
  • Feature: Full tvOS support with Xcode 7.1
  • Bugfix: Default number of lines to skip in RadarChart was wrong
  • Bugfix: avoidFirstLastClipping has weird offsets sometimes
  • Bugfix: Fixed a case where of highlight not clearing on first tap
  • Bugfix: Fixes a potential crash in drawCircles()
  • Bugfix: Fixed deltaX in combined chart was not calculated in some cases
  • Bugfix: Fixed a bug where panning was disabled in BarLineChart if a drag offset was set
  • Improvements: More "dynamic" control over position of MarkerView
  • Other minor bugfixes

PieChart, LimitLine & interaction improvements - 2015-10-15 21:59:24

  • LimitLine improvements (more customizeability)
  • Highlight improvements
  • Animation bug fixes
  • PieChart offset fixes
  • PieChart center text now supports NSAttributedString (centerAttributedText is recommended instead of centerText)
  • Support for custom alpha for pie hole
  • Minor bugfixes
  • Some code cleanup
  • Code safety improvements using Swift 2.0 (guard etc.)
  • Changed renderer delegates into DataProvider protocols, that more closely matches the Android version, and allows more flexibility.
  • Custom minimum offset for Bar/Line/Pie charts
  • Support for legends above the chart
  • A new tvOS target

Critical fix for Radar chart, minor bugfixes and improvements - 2015-10-02 06:08:17

This is an intermediate release, with the following:

  1. CRITICAL fix for Radar Chart, for a bug that caused an endless loop due to skipWebLineCount feature.
  2. Custom minimum offset for Bar/Line/Pie charts
  3. Support for legends above the chart
  4. A new tvOS target
  5. Other minor features
  6. Other minor bugfixes and improvements

Swift 2.0, minor new features and bugfixes - 2015-09-21 21:16:50

  • Moved to Swift-2.0 (Xcode 7)
  • PieChart and HorizontalBarChart now support Markers
  • Introducing FillFormatter for individual LineDataSets
  • Introducing XAxisValueFormatter for custom XAxis label formatting
  • General bugfixes and improvements

This release contains the binaries of 2.1.4a release, for Carthage users. This is to prevent the hanging Radar chart problem. Since Carthage does not support letters after version numbers, we can't rely on 2.1.4a for Carthage users.

Minor fixes - 2015-08-05 08:52:29

This is just to catch up with missing changes in the Android version, and a few very minor fixes since then (Mainly concerning highlights).

Bugfixes & Enhancements - 2015-07-26 19:58:54

  • Stacked BarChart fixes for mixed positive/negative values
  • Fixed ChartMarker position in BarChart
  • Feature to allow forcing fixed number of YAxis labels
  • General bugfixes

Doubles, more customization, auto-scaling min/max - 2015-07-26 17:57:28

  • Moved to using doubles instead of floats
  • Auto-scaling y axis' min/max
  • Customizing legend values
  • Controlling extra offsets caused by the legend
  • Negative values in stacked bar charts
  • Word wrapping in pie chart's center text
  • Word wrapping in "below" legends
  • Support for multi-line text in x-axis
  • Better cooperation with scrollviews (Bar/Line charts automatically, Pie/Radar charts through enabling two-finger rotation in pie chart)
  • Viewport support for max scale on x axis
  • Many other small features
  • More bug fixes