我想创建一个带有 IOS 绘图的饼图,我已经下载了框架,但它从 plist 文件中获取数据,它只是静态的解决这个问题,我不明白这个情节部分的填充值是如何产生的。这是在单独的视图中我想要在我现有的视图控制器中
#import "PieChartViewController.h"
#import "PCPieChart.h"
@implementation PieChartViewController
- (id)init
{
self = [super init];
if (self)
{
[self.view setBackgroundColor:[UIColor colorWithWhite:1 alpha:1]];
[self.titleLabel setText:@"Pie Chart"];
int height = [self.view bounds].size.width/3*2.; // 220;
int width = [self.view bounds].size.width; //320;
PCPieChart *pieChart = [[PCPieChart alloc] initWithFrame:CGRectMake(([self.view bounds].size.width-width)/2,([self.view bounds].size.height-height)/2,width,height)];
[pieChart setAutoresizingMask:UIViewAutoresizingFlexibleLeftMargin|UIViewAutoresizingFlexibleRightMargin|UIViewAutoresizingFlexibleTopMargin|UIViewAutoresizingFlexibleBottomMargin];
[pieChart setDiameter:width/2];
[pieChart setSameColorLabel:YES];
[self.view addSubview:pieChart];
[pieChart release];
if ([[UIDevice currentDevice] userInterfaceIdiom]==UIUserInterfaceIdiomPad)
{
pieChart.titleFont = [UIFont fontWithName:@"HelveticaNeue-Bold" size:30];
pieChart.percentageFont = [UIFont fontWithName:@"HelveticaNeue-Bold" size:50];
}
// NSString *sampleFile = [[[NSBundle mainBundle] bundlePath] stringByAppendingPathComponent:@"sample_piechart_data.plist"];
// NSDictionary *sampleInfo = [NSDictionary dictionaryWithContentsOfFile:sampleFile];
NSMutableArray *components = [NSMutableArray array];
for (int i=0; i<[[components] count]; i++)
{
NSDictionary *item = [[sampleInfo objectForKey:@"data"] objectAtIndex:i];
PCPieComponent *component = [PCPieComponent pieComponentWithTitle:[item objectForKey:@"title"] value:[[item objectForKey:@"value"] floatValue]];
[components addObject:component];
if (i==0)
{
[component setColour:PCColorYellow];
}
else if (i==1)
{
[component setColour:PCColorGreen];
}
else if (i==2)
{
[component setColour:PCColorOrange];
}
else if (i==3)
{
[component setColour:PCColorRed];
}
else if (i==4)
{
[component setColour:PCColorBlue];
}
}
[pieChart setComponents:components];
}
return self;
}