xandhen / IWantPieChart

Simple pie chart component for iOS
1 stars 0 forks source link

IWantPieChart

A simple pie chart component that allows you to show quarts drawn pie charts using either an array of values or a delegate protocol.

If the radius for the pie is not supplied it will automatically scale to fit within the supplied frame.

Selection of slices can be either single selection or multi-selection. The offset from the pie center to distinguish the selection is customizable.

Slice colors are optional and will be automatically generated based on a "base" color if omitted on any element.

Currently there is no support for legends, but the text part of the slice is supported in the interface.

Sorry, but this is a non ARC component for now.

Properties

UIColor *sliceBaseColor

Holds the base color that will be used for slice color generation when a color is not supplied for a slice.

UIColor *textColor

Holds the text color that will be used to show the selected unit to display.

UnitDisplayType unitToDisplay

Controls what will be shown on the pie slices if anything. Can be one of the following:

CGFloat innerRadius

If the inner radius is set the pie chart will be drawn as a donut where the inner radius specifies the radius of the hole in the donut.

CGFloat selectedOffset

Sets the offset from the center point at which a selected slice will be drawn.

BOOL allowMultiSelect

Indicates if more than one slice can be selected.

Functions

(id) initWithFrame:(CGRect)frame

Default initialization. Will calculate maximum radius to fit within the frame.

(id) initWithFrame:(CGRect)frame pieCenter:(CGPoint)center pieRadius:(CGFloat)radius

Optional initialization where center point within the frame and the radius can be supplied.

(void) addSlices:(int)count WithValues:(CGFloat*)values

Add a number of slices with values supplied in an array.

(void) addSliceWithValue:(CGFloat)value

Add a slice with a given value.

(void) addSliceWithValue:(CGFloat)value Text:(NSString*)text

Add a slice with a given value and text.

(void) addSliceWithValue:(CGFloat)value Color:(UIColor*)color

Add a slice with a given value and color.

(void) addSliceWithValue:(CGFloat)value Text:(NSString)text Color:(UIColor)color

Add a slice with a given value, text and color.

(void) selectSliceAtIndex:(NSInteger)index

Select the slice at the given index. Make sure that the selectedOffset property is set.

How to use

Drop the IWantPieChart.h and IWantPieChart.c files into your project. Include the IWantPieChart.h in the view/controller that will use it.

Create and initialize the chart using [[IWantPieChart alloc] initWithFrame:frame]

Add one or more slices using addSliceWithValue or addSlices:WithValue.

All done, further configuration is optional.