For a simple pie chart, even with the aforementioned animations, Core Plot is not necessary. If you only want a Core Plot solution, then please disregard this answer. However, here is a simple solution that requires no external packages or even any frameworks.
Create a UIView called PieChartView. In PieChartView.h:
#import <UIKit/UIKit.h>
@interface PieChartView : UIView {
float zeroAngle;
NSMutableArray *valueArray;
NSMutableArray *colorArray;
}
@property (nonatomic) float zeroAngle;
@property (nonatomic, retain) NSMutableArray *valueArray;
@property (nonatomic, retain) NSMutableArray *colorArray;
@end
Then the implementation in PieChartView.m:
#import "PieChartView.h"
@implementation PieChartView
@synthesize zeroAngle;
@synthesize valueArray, colorArray;
- (id)initWithFrame:(CGRect)frame {
if ((self = [super initWithFrame:frame])) {
}
return self;
}
- (void)drawRect:(CGRect)rect {
CGContextRef context = UIGraphicsGetCurrentContext();
// DETERMINE NUMBER OF WEDGES OF PIE
int wedges = [valueArray count];
if (wedges > [colorArray count]) {
NSLog(@"INSUFFICENT COLORS FOR PIE CHART: Please add %d additional colors.",wedges-[colorArray count]);
for (int i=[colorArray count] ; i<wedges ; ++i) {
[colorArray addObject:[UIColor whiteColor]];
}
}
// DETERMINE TOTAL VOLUME OF PIE
float sum = 0.0;
for (int i=0; i<wedges ; ++i) {
sum += [[valueArray objectAtIndex:i] floatValue];
}
float frac = 2.0*M_PI/sum;
// DETERMINE CENTER AND MAXIMUM RADIUS OF INSCRIBED CIRCLE
int center_x = rect.size.width/2.0;
int center_y = rect.size.height/2.0;
int radius = (center_x > center_y ? center_x : center_y);
// DRAW WEDGES CLOCKWISE FROM POSITIVE X-AXIS
float startAngle=zeroAngle;
float endAngle=zeroAngle;
for (int i=0; i<wedges; ++i) {
startAngle = endAngle;
endAngle += [[valueArray objectAtIndex:i] floatValue]*frac;
[[colorArray objectAtIndex:i] setFill];
CGContextMoveToPoint(context, center_x, center_y);
CGContextAddArc(context, center_x, center_y, radius, startAngle, endAngle, 0);
CGContextClosePath(context);
CGContextFillPath(context);
}
}
- (void)dealloc {
[valueArray release];
[colorArray release];
[super dealloc];
}
@end
Now you can bind the float zeroAngle to the accelerometer in any way you wish to achieve the desired animation.