2015-08-26 45 views
0

相关视图控制器为H文件如何修正Coreplot饼图问题64位版本VS 32位版本

#import <UIKit/UIKit.h> 
#import "StudentModel.h" 
#import "CorePlot-CocoaTouch.h" 


@interface AttendenceViewController : UIViewController  <UITabBarDelegate,UITableViewDataSource,CPTLegendDelegate,CPTPieChartDataSource,CPTPieChartDelegate> 

@property (strong,nonatomic) StudentModel *studentA; 
@property (strong,nonatomic) NSDictionary *studentAttendanceDetails; 
@property (weak, nonatomic) IBOutlet UIView *graphContainer; 

用于相关视图控制器

#import "AttendenceViewController.h" 

@interface AttendenceViewController() 
@property (nonatomic,strong) CPTGraphHostingView *hostView; 
@property (nonatomic,strong) CPTTheme *selectedTheme; 

-(void)initPlot; 
-(void)configureHost; 
-(void)configureGraph; 
-(void)configureChart; 
-(void)configureLegend; 
@end 

@implementation AttendenceViewController 

- (void)viewDidLoad { 
[super viewDidLoad]; 
// Do any additional setup after loading the view. 
// float attendanceTotal = [self.studentA.percentageAttendance floatValue]; 
// float authorisedAbsences = [self.studentA.authorisedAbsences floatValue]; 
// float unathorisedAbsences = [self.studentA.unautherisedAbsences floatValue]; 

self.studentAttendanceDetails = [NSDictionary dictionaryWithObjectsAndKeys:self.studentA.percentageAttendance,@"totalAttendance",self.studentA.authorisedAbsences,@"authorisedAbsences",self.studentA.unautherisedAbsences,@"unauthorisedAbsences", nil]; 
NSLog(@"%@",self.studentAttendanceDetails); 
} 

-(void)viewDidAppear:(BOOL)animated 
{ 
[super viewDidAppear:animated]; 
[self initPlot]; 

} 

#pragma mark Core Plot Initialisation Methods 
-(void)initPlot 
{ 
[self configureHost]; 
[self configureGraph]; 
[self configureChart]; 
[self configureLegend]; 

} 

-(void)configureHost; 
{ 
CGRect parentRect = self.graphContainer.bounds; 
self.hostView = [(CPTGraphHostingView*)[CPTGraphHostingView alloc]initWithFrame:parentRect]; 
self.hostView.allowPinchScaling=NO; 
[self.graphContainer addSubview:self.hostView]; 
} 
-(void)configureGraph; 
{ 
//create and initialise the graph 
CPTGraph *graph = [[CPTXYGraph alloc]initWithFrame:self.hostView.bounds]; 
self.hostView.hostedGraph=graph; 
graph.paddingLeft=0.0f; 
graph.paddingTop=0.0f; 
graph.paddingRight=0.0f; 
graph.paddingBottom=0.0f; 
graph.axisSet=nil; 
//set up the text styles 
CPTMutableTextStyle *textStyle = [CPTMutableTextStyle textStyle]; 
textStyle.color= [CPTColor grayColor]; 
textStyle.fontName [email protected]"Helvetica-Bold"; 
textStyle.fontSize=16.0f; 
//configure the title 
NSString *title = @"Student Attendance"; 
graph.title=title; 
graph.titleTextStyle=textStyle; 
graph.titlePlotAreaFrameAnchor= CPTRectAnchorTop; 
graph.titleDisplacement= CGPointMake(0.0f, -12.0f); 
self.selectedTheme = [CPTTheme themeNamed:kCPTPlainWhiteTheme]; 
[graph applyTheme:self.selectedTheme]; 

} 
-(void)configureChart; 
{ 
//get reference to graph 
CPTGraph *graph = self.hostView.hostedGraph; 
//create chart 
CPTPieChart *pieChart = [[CPTPieChart alloc]init]; 
pieChart.delegate=self; 
pieChart.dataSource=self; 
pieChart.pieRadius=(self.hostView.bounds.size.height*0.9)/3; 
pieChart.identifier= graph.title; 
pieChart.startAngle = M_PI_4; 
pieChart.sliceDirection=CPTPieDirectionClockwise; 
//gradient 
CPTGradient *overlayGradient = [[CPTGradient alloc]init]; 
overlayGradient.gradientType=CPTGradientTypeRadial; 
overlayGradient=[overlayGradient addColorStop:[[CPTColor blackColor]colorWithAlphaComponent:0.0] atPosition:0.9]; 
overlayGradient=[overlayGradient addColorStop:[[CPTColor blackColor]colorWithAlphaComponent:0.4] atPosition:1.0]; 
pieChart.overlayFill = [CPTFill fillWithGradient:overlayGradient]; 
[graph addPlot:pieChart]; 
} 
-(void)configureLegend; 
{ 

} 


#pragma mark Core Plot Datasource Methods 

-(NSUInteger)numberOfRecordsForPlot:(CPTPlot *)plot 
{ 
return [self.studentAttendanceDetails count]; 
} 

-(NSNumber*)numberForPlot:(CPTPlot *)plot field:(NSUInteger)fieldEnum recordIndex:(NSUInteger)idx 
{ 
if (CPTPieChartFieldSliceWidth == fieldEnum) 
{ 
    NSArray *values = [self.studentAttendanceDetails allValues]; 
    return [values objectAtIndex:idx]; 

} 
return [NSDecimalNumber zero]; 
} 

-(CPTLayer*)dataLabelForPlot:(CPTPlot *)plot recordIndex:(NSUInteger)idx 
{ 
static CPTMutableTextStyle *labelText = nil; 
if (!labelText) { 
    labelText= [[CPTMutableTextStyle alloc] init]; 
    labelText.color = [CPTColor grayColor]; 
} 

NSString *labelValue = nil; 

switch (idx) { 

    case 0:{ 
     NSString *unauthorised= [self.studentAttendanceDetails objectForKey:@"unauthorisedAbsences"]; 
     NSLog(@"%@",unauthorised); 
     if ([unauthorised isEqualToString:@"0.00"]) { 
      labelText=nil; 
     } 
     labelValue = [NSString stringWithFormat:@"%@",[self.studentAttendanceDetails objectForKey:@"unauthorisedAbsences"]]; 
    } 
     break; 

    case 1: 
     labelValue = [NSString stringWithFormat:@"%@",[self.studentAttendanceDetails objectForKey:@"totalAttendance"]]; 
        break; 
     case 2: 
     labelValue = [NSString stringWithFormat:@"%@",[self.studentAttendanceDetails objectForKey:@"authorisedAbsences"]]; 

     break; 
      } 
return [[CPTTextLayer alloc] initWithText:labelValue style:labelText]; 


} 

-(NSString*)legendTitleForPieChart:(CPTPieChart *)pieChart recordIndex:(NSUInteger)idx 
{ 
return @"Student Attendance"; 
} 

- (void)didReceiveMemoryWarning { 
[super didReceiveMemoryWarning]; 
// Dispose of any resources that can be recreated. 
} 

图像的M档结果当模拟器被设置为iPhone 5和运行enter image description here(即32位)

结果的图像时模拟器被设置为的iPhone 5S或更高(即64位)

enter image description here

的问题是如何我调整代码在用于视图控制器以确保输出的执行文件相同的32位和64位运行?

回答

1

词典没有定义的顺序。 allValues阵列在每个平台上可能都不相同。对于这个应用程序,根本不需要在字典中存储值。只需根据索引从数据源中返回authorisedAbsencesunautherisedAbsences即可。

+0

我会看看这个谢谢,但这并不能解释为什么饼图绘制的颜色已经改变了,或者它会改变吗? – jon

+0

是的,因为两个平台之间的实现差异可能会使'allValues'数组的顺序不同。无论如何,这不是你应该依赖的。 –

相关问题