• Stars
    star
    509
  • Rank 83,876 (Top 2 %)
  • Language
    Swift
  • License
    Apache License 2.0
  • Created over 7 years ago
  • Updated about 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Easy to use and highly customizable pie charts library for iOS

PieCharts

Version Carthage compatible License

Easy to use and highly customizable pie charts library for iOS

Swift 4.2, iOS 8+

Video

ScreenShotScreenShot

Features:

  • Customizable slices
  • Add overlays using simple UIViews
  • Interactive
  • Animated
  • Dynamic slice insertion
  • Reusable components via extensible layer system
  • Configurable in interface builder
  • Legends. This is in a separate project to keep things focused and reusable.

Installation

CocoaPods

Add to your Podfile:

use_frameworks!
pod 'PieCharts'

Carthage

Add to your Cartfile:

github "i-schuetz/PieCharts"

Usage

Basic chart:

@IBOutlet weak var chartView: PieChart!

chartView.models = [
    PieSliceModel(value: 2.1, color: UIColor.yellow),
    PieSliceModel(value: 3, color: UIColor.blue),
    PieSliceModel(value: 1, color: UIColor.green)
]

Configurable in interface builder, with live update of the view:

ScreenShot

Overlays:

Overlays are implemented using layers. There are several built in layers and you also can implement your own ones.

To add text e.g. text labels inside the slices + text with lines outside, simply:

chartView.layers = [PiePlainTextLayer(), PieLineTextLayer()]

Each layer has its own customization options. For example, here we customize the plain labels layer:

let textLayerSettings = PiePlainTextLayerSettings()
textLayerSettings.viewRadius = 55
textLayerSettings.hideOnOverflow = true
textLayerSettings.label.font = UIFont.systemFont(ofSize: 8)

let formatter = NumberFormatter()
formatter.maximumFractionDigits = 1
textLayerSettings.label.textGenerator = {slice in
    return formatter.string(from: slice.data.percentage * 100 as NSNumber).map{"\($0)%"} ?? ""
}

let textLayer = PiePlainTextLayer()
textLayer.animator = AlphaPieViewLayerAnimator()
textLayer.settings = textLayerSettings

This is the custom views layer, which makes possible to create custom views:

let viewLayer = PieCustomViewsLayer()

let settings = PieCustomViewsLayerSettings()
settings.viewRadius = 135
settings.hideOnOverflow = false
viewLayer.settings = settings

viewLayer.viewGenerator = {slice, center in
    let myView = UIView()
    // add images, animations, etc.
    return myView
}

Interactivity, events:

Conform to PieChartDelegate to react to interaction and other events:

func onGenerateSlice(slice: PieSlice)
func onStartAnimation(slice: PieSlice)
func onEndAnimation(slice: PieSlice)
func onSelected(slice: PieSlice, selected: Bool)

Dynamic slice insertion:

chartView.insertSlice(index: 1, model: PieSliceModel(value: 5, color: UIColor.blue))

Contributing

  1. Fork
  2. Commit changes to a branch in your fork
  3. Push your code and make a pull request

Outlook

The layer system can be abstracted a step further in order to make the slices themselves be in a layer. This way we can combine multiple slice-layers to create more complex types of pie charts.

Credits

The food images used in the demo are from freepik.com, and flaticon.com/authors/madebyoliver

Created By:

Ivan Schütz

License

SwiftCharts is Copyright (c) 2017 Ivan Schütz and released as open source under the attached Apache 2.0 license.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.

More Repositories

1

SwiftCharts

Easy to use and highly customizable charts library for iOS
Swift
2,496
star
2

rust_android_ios

Android / iOS app with shared Rust logic
Rust
203
star
3

tableview_infinite

Infinite scrolling for UITableView in Swift, with background thread to request new data, and loading footer.
Swift
83
star
4

clojushop

Online shop backend/api written in Clojure
Clojure
46
star
5

rest_client_ios

Rest client / shopping app for iOS written in Swift
Swift
35
star
6

ChartLegends

Easy to use and highly customizable chart legends
Swift
34
star
7

yew-d3-example

Example using a d3 chart with Yew
Rust
22
star
8

map_areas

Android maps v2 circles library
Java
19
star
9

swaplink

Site to perform peer to peer atomic swaps on the Algorand blockchain
Rust
16
star
10

wasm-rust-d3

Fetch data with Rust/WASM and show with JS/d3 example
Rust
15
star
11

Android_OpenGL_Picking

Android OpenGL picking example
Java
9
star
12

dart_copy_with_plugin

Dart copyWith generation plugin
Kotlin
8
star
13

UserDefaults

Convenient wrapper for NSUserDefaults, in Swift
Swift
7
star
14

algorand-yew-example

Shows how to use the Algorand Rust SDK in a Yew app
Rust
4
star
15

Android_Coverflow_GL

Android coverflow with OpenGL 1.0 (incomplete)
Java
4
star
16

algonaut-myalgo-yew-template

Template to sign Algonaut transactions with My Algo wallet in a Yew application.
Rust
4
star
17

tamagotchi_clojure

Stateless command line tamagotchi example, written in Clojure
Clojure
4
star
18

dmmf

Haskell
2
star
19

webgl_chatroom

Basic chat functionality, using websockets, in 3D scene
JavaScript
2
star
20

icarousel_demo

Swift example of iCarousel for iOS
Objective-C
2
star
21

scene_kit_pick

Scene Kit example for OS X, with picking / highlighting (Swift)
Swift
2
star
22

my-algo-rust-adapter

Adapter to call My Algo from Rust
Rust
2
star
23

algo-prompt

Yew component to display Algorand transaction prompts
Rust
2
star
24

algonaut-react

Example for using the Algorand Rust SDK in a React JS app
JavaScript
2
star
25

export_ts_macro

Rust
1
star
26

scene_kit_pick_ios

Scene Kit example for iOS, with picking / highlighting (Swift)
Swift
1
star
27

algo-wallets

JavaScript
1
star
28

algonaut_ios

Shows how to use Algonaut in an iOS app
Rust
1
star