GithubHelp home page GithubHelp logo

owlmafia / piecharts Goto Github PK

View Code? Open in Web Editor NEW
512.0 14.0 92.0 335 KB

Easy to use and highly customizable pie charts library for iOS

License: Apache License 2.0

Ruby 0.97% Swift 98.15% Objective-C 0.88%
pie-chart graph chart ios swift swift-3

piecharts's Introduction

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.

piecharts's People

Contributors

arbitur avatar guerrix avatar hyunminch avatar jrafaelm avatar markus-mohemian avatar nitrodamsel avatar owlmafia avatar simonwaldherr avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

piecharts's Issues

How to add a string to Pie Slice Model value?

for the below:

PieSliceModel(value: 30, color: colors[2])

I need the 30 to appear on the Pie Chart as "30 g". The question is how to to do it.

Can I do it using textLayerSettings?

Cheers,
adam

Extra/Less slices when UIcollectionView is scrolled

I am using this library to draw chart for datas available in UIcollectionView. When I scroll or refresh list old slices are changed to new (They contain more or less slices) and old slices are added in another cell chart

How to set the text of a PiePlainTextLayer

hey guys

I'm trying to add labels to my pie slices using chartView.layers = [PiePlainTextLayer(), PieLineTextLayer(), PieLineTextLayer()], however I'm not sure how to set the text for each layer for my corresponding three slices. These are the only properties I see for a PiePlainTextLayer:
screen shot 2017-12-12 at 11 46 44 am

Any thoughts?

Thanks

add button

How to add button inside the pie chart circle?

Ask for New Release

Hi, our team was hoping to use PieCharts through Cocoapods, with my pull request merged in the project. The current release does not have options for using PieChart without Xibs, while our team's internal policy is to not use Xibs.

Could you do us a favor of releasing a new version of PieCharts?

Thanks!

Parameter name change for CAMediaTimingFunction in PieSliceLayer.swift

Compiler throws the following error on Xcode 10 and above
CAMediaTimingFunction parameter is changed from
anim.timingFunction = CAMediaTimingFunction(name: CAMediaTimingFunctionName.easeOut)
to
anim.timingFunction = CAMediaTimingFunction(name: kCAMediaTimingFunctionEaseOut)
Kindly release the updated pod with this change.

failed to render and update auto layout status

error: IB Designables: Failed to render and update auto layout status for viewcontroller : dlopen(PieCharts.framework, 1): no suitable image found. Did find:
PieCharts.framework: required code signature missing for 'PieCharts.framework'

Gradient?

Hello,
Is it possible to add a gradient to a slice in stead of a color?
If yes, can you please point out where i can do that.

Thanks in advance.

A proper way to get the slices

Hey, I was looking for a way to get the slices from a PieChart so that I could select one of them programmatically... I just did a kind of a hacky way of dealing with it, take a look at it... but if you see some way better to do it just inform me and I change it to your way.

Personalizate DoughnutDemo

It is not a real problem but a clarification

Hi, i'm using your library is good and can be used in many ways!

I'm using your library in my project but first i'm trying in your demo project, i'm looking to personalizate the Doughnut but for me your library is not easy, i tried to modificate something and i'm getti what i want, but not at all.

I'm gonna to personalizate the slices, where i want only two slices, 1st is the main and the 2nd will be modificate by code frequently(for that i can remove the last and create a new or i can modificate the currently slice), i want a single percentage in the middle (i have already set the text in the middle point of the doughnut but when i add slice i have a label over another).

Have you some suggestion for my question?

Thank you in advance.

inner and outer radius not updating when changing them via code

I'm trying to add this chart to my app but I can't set the size using storyboard because it needs to auto scale with constraints. So I tried doing it programmatically but whatever I do it doesn't seem to update.

@IBOutlet weak var profileChartView: PieChart!
profileChartView.outerRadius = 40 //These are just demo values
profileChartView.innerRadius = 50

Aligning Slice labels to always stay in the middle of slices

Hey folks,

I'm trying to place slice labels in the middle of my slices, however when I redraw the slices from it's data source update, the labels become off center and sometimes slides outside of the slice completely.

Is there a way to properly anchor a slice's label to the middle and have it stay anchored to the slice's view.center?

Any help would be much appreciated

Updating pie chart when data changed

The value property of a model in the pie chart is a 'let' constant. So that cannot be modified.
Other way i could figure out was to set models to empty and create models again, but that added two piecharts, one on top of another.

Is there a clear precise way to update the chart with changing the values of the pie chart models?

Expected Behavior: The pie chart should update the slices when the data is changed.
Observed Behavior: The value property cannot be set. The updated chart shows up only when the app is started again.

How do you recommend to update the chart when the data is changed?

UPDATE:

I am now able to update the chart, but I am still unable to show just the updated values in the text layer. The older text layers also show up despite removing all of them before setting the new labels.

pieChart.models = []
pieChart.removeSlices()
// now create models -> this updates the chart. However the previous text layers still show up.

how i can make center empty space smaller

hi
how i can make empty space in chart smaller to fit my view
chart not fit height and width of my view

Edit:
i founded solution
by changing innerRadius and outerRadius
thank you for simplest chart for Swift

Can I know how to use labelGenerator for using customized label?

I want to use label with slice name and percentage that are styled differently (e.g. Apple 27%, Samsung 12%... ) on textLineChart with NSmutableAttributedString,
so I found this code in PieChartLabelSettings.swift

// Optional custom label - when this is set presentations settings (textColor, etc.) are ignored
public var labelGenerator: ((PieSlice) -> UILabel)?

Can I use 'labelGenerator' for making customized label? or is there any method?

Cant add data to piechart properly

I ma facing an issue while adding data to pie chart from coredata, I am inserting new data with the method insertSlice and then lineTextLayerSettings.label.textGenerator this method is called and in it i am using for loop fetch data and the pie is inserted at 0 and the text is inserted at last. Can u help in this matter?

Question about text?

Hi,
Thanks for the great library!
I am not a very experienced programmer yet and i would like to ask you how to get the outer labels of the doughnut to also display text in addition to the value?

I hope you can help me and sorry for my ignorance.

PieChart view is not getting updated.

My app allows user to add a new value that is to added to the pie chart on home. So, even after passing a new set of model the pie chart is not getting updated.

Rotating the pie chart

Hi Ivan, I am curious if there would be a way to make the pie chart rotate so the slice selected is at the top position when it expands.

static slices

I want the slices to be static not to move up when it is selected
So please help me how can i do it

Chart not centered if simulator screen size is not the storyboard screen size

I'm using PieCharts within a StackView Controller. I designed my view for iPhone SE. When I use the view on a iPhone with a bigger screen than the SE (in extreme iPhone 8 plus) the pie chart is not centered anymore.

I tried a lot, but cannot center the chart. Is there a chance to do it, or do I have to work around.

IBDesignable Error

error: IB Designables: Failed to render and update auto layout status for PortfolioGraphViewController (tX7-E5-fCS): dlopen(TGPControls.framework, 1): no suitable image found. Did find:
TGPControls.framework: required code signature missing for 'TGPControls.framework'

Failed to render and update auto layout status

error: IB Designables: Failed to render and update auto layout status for viewcontroller : dlopen(PieCharts.framework, 1): no suitable image found. Did find:
PieCharts.framework: required code signature missing for 'PieCharts.framework'

Xcode 9.4
Swift 4.1

PieCharts Not Initializable Without Nib Files

Hi, I wanted to used PieCharts without any xib files (one of our team's project protocols.) However, it seems like PieChart is not usable without the use of xib files.

I think the probable cause would be within PieChart.swift, where convenience init() does not seem to call sharedInit() in PieChart.swift, and the overridden init(frame: CGRect) { ... } is declared internally.

It would be great if you can look into it. Thanks. 👍

Dynamically insert PieCustomViewsLayer?

Can I do something like:

func onSelected(slice: PieSlice, selected: Bool) {
    if selected {
        chartView.layers = [createCustomViewsLayer()]
    }
 }

Also also tried adding it while creating the chartView but then when I hide all layers by default (container view), I am not able to set isHidden=false in onSelected

I am trying to add a uibezierpath around the selected slice, something like this:

file

Deselecting slices upon selecting new slice

Is there a way to deselect other selected slices when selecting a new one? I'm trying to make the last selected slice animate back into the pie chart when I select another.

How can i change radius?

I want to change chart radius size but i can't do it.

let viewLayer = PieViewLayer()
let settings = PieViewLayerSettings()
settings.viewRadius = 70
settings.hideOnOverflow = false
viewLayer.settings = settings

responseChart.layers = [viewLayer, responseTextLayer]

is'nt it true?

Slices not going out so far?

I have this problem where when a press on a slice it goes out too far. Like the picture below,
screen shot 2017-07-22 at 4 36 21 pm

I am wondering if it is possible to make it not go out so far?

want to change start angle

I'm using it well but I want to change angle that start point of first pie slice.

is there a method to change angle of chart in release version (0.04) ?

Error while adding the animator given in Readme

Im getting the following buildtime error on textLayer.animator = AlphaPieViewLayerAnimator() this line of code.
'AlphaPieViewLayerAnimator' initializer is inaccessible due to 'internal' protection level

Updating slices

Is there currently a way to update the value of a slice without completely redrawing the graph?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.