Skip to content

An open-source library for building customisable ring charts in Swift projects.

License

Notifications You must be signed in to change notification settings

subhronilsaha/CPRingChart

Repository files navigation

CPRingChart

CI Status Version License Platform

Frame 1

What is CPRingChart?

CPRingChart is a customisable Swift library for creating ring charts quickly and with just a few lines of code. You can add it to your Swift project using Cocoapods.

The most widely used library for making these kind of charts, in my opinion, is probably the amazing 'Charts' library by Daniel Gindi (https://github.com/danielgindi/Charts), where you would essentially create a hollow pie-chart. But unfortunately it does not provide the option to add rounded caps to your slices.

Hence this library aims to solve that problem.

Installation

CPRingChart is available through CocoaPods. To install it, simply add the following line to your Podfile:

pod 'CPRingChart'

and from your Terminal, run

pod install

Usage

You can read this explanation post that I wrote on Dev.to for better reference : https://dev.to/subhronilsaha/a-practical-guide-to-creating-ring-charts-using-the-cpringchart-library-27oa

1. Using Storyboard / Interface Builder

- Drop a UIView into your Storyboard file.
- Change its class to `CPRingChart`.
- Link it to your ViewController.swift.
- Set the properties mentioned below.
- Call `reloadChart()` method of your `CPRingChart` instance (ie, IBOutlet).

NOTE: In v0.1.0, please locate the CPRingChart.swift file in Pods (Project) -> Pods (Directory) -> CPRingChart -> CPRingChart.swift and add the public keyword before the class definition & variables not marked private. This is fixed in v0.1.1

You can change the following properties:

  • sections : Double

    • required
    • default = 0
    • Number of sections or number of rings in the chart
  • values : [Double]

    • required
    • default = [Double]()
    • Holds the list of values corresponding to the ring's progress.
    • Can be any value. Not necessary to sum to 100.
  • fillColors = [UIColor]

    • required
    • default = [UIColor]()
    • List of ring fill colors
    • Count should be equal to sections
  • spacing : Double

    • default = 0.05 (ie 5%)
    • Spacing between the rings.
    • Range : 0 to 1
    • Values should be in percentage. ie, spacing = 0.05 = 5% spacing
  • ringWidth : CGFloat

    • default = 10
    • Width of a ring
  • roundedCap : Bool

    • default = true
    • True to make cap rounded
  • centerFillColor : UIColor

    • default = UIColor.clear
    • Inner circle fill color for all charts.

Screenshots

Screenshot 2021-08-10 at 6 06 36 PM

Author

Subhronil Saha, subhronilsaha26@gmail.com

License

CPRingChart is available under the MIT license. See the LICENSE file for more info.

CPRingChart uses CircleProgressView under the hood. Check out the repo CircleProgressView by CardinalNow: https://github.com/CardinalNow/iOS-CircleProgressView