Blog

Thoughts on mobile app development.

Pretty Pie Charts with XYPieChart

XYPieChart is a simple to use, great looking component for drawing pie charts in iOS apps. I recently needed a pie chart for an app I’m working on, and I can honestly say this was one of the nicest experiences I’ve ever had with a 3rd party component. This video on Vimeo gives you a nice overview of it’s capabilities.

XYPieChart

Out of the box, XYPieChart looks fantastic, with a nice selection of colours and some snazzy animations. Of course, this is all customisable – select whatever colours you like, turn animations on or off, change the fonts – most of these customisations are just a single line of code. In fact, I only have a total of 16 lines of code in my UIViewController for displaying, customising and updating my pie chart.

XYPieChart uses the datasource and delegate pattern, which should be familiar, and the clean and simple API is pretty much self explanatory. For example:

[code]
- (NSUInteger)numberOfSlicesInPieChart:(XYPieChart *)pieChart {
return self.values.count;
}

- (CGFloat)pieChart:(XYPieChart *)pieChart valueForSliceAtIndex:(NSUInteger)index {
NSNumber* value = self.values[index];
return value.doubleValue;
}
[/code]

Couldn’t be easier, right?

If you ever have a need for any sort of pie chart in your iOS apps, I would definitely recommend giving XYPieChart a go.

Submit a Comment

Your email address will not be published. Required fields are marked *