2012-09-08 38 views
9

Tôi làm việc trong ứng dụng biểu đồ thanh đơn giản, dùng để phát triển ứng dụng này, sau đó tôi cố gắng thực hiện các biểu đồ thanh nhưng tôi nhận được vấn đề tìm thấy trongCách triển khai biểu đồ thanh trong iPhone?

[__NSCFConstantString sizeWithTextStyle:]: unrecognized selector sent to instance 0x7fb4c' 
    First throw call stack: 

Làm thế nào để sửa lỗi này? hãy giúp tôi

Cảm ơn trước

Tôi cố gắng này:

Viewcontroller.h

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


@interface GraphViewController : UIViewController <CPTPlotDataSource> 
{ 
    CPTXYGraph *barChart; 
    NSTimer *timer; 
    NSMutableArray *samples; 
} 

-(void) getGraphValues; 

@end 

Viewcontroller.m

- (void)viewDidLoad 
    { 
     [super viewDidLoad]; 

     self.view.backgroundColor=[UIColor whiteColor]; 
     self.title = @"Sample"; 
     self.navigationController.navigationBar.barStyle = UIBarStyleBlack; 
     [self.navigationController setNavigationBarHidden:NO]; 

     [self getGraphValues]; 

     double xAxisLength = [samples count]; 

     barChart = [[CPTXYGraph alloc] initWithFrame:CGRectMake(0, 0, 320, 380)]; 

     barChart.plotAreaFrame.borderLineStyle = nil; 
     barChart.plotAreaFrame.cornerRadius = 0.0f; 

     barChart.paddingLeft = 0.0f; 
     barChart.paddingRight = 0.0f; 
     barChart.paddingTop = 0.0f; 
     barChart.paddingBottom = 0.0f; 

     barChart.plotAreaFrame.paddingLeft = 60.0; 
     barChart.plotAreaFrame.paddingTop = 40.0; 
     barChart.plotAreaFrame.paddingRight = 10.0; 
     barChart.plotAreaFrame.paddingBottom = 40.0; 

     barChart.title = @"Sample Innovations"; 

     CPTMutableTextStyle *textStyle = [CPTTextStyle textStyle]; 
     textStyle.color = [CPTColor grayColor]; 
     textStyle.fontSize = 16.0f; 
     textStyle.textAlignment = CPTTextAlignmentCenter; 
     barChart.titleTextStyle = textStyle; // Error found here 
     barChart.titleDisplacement = CGPointMake(0.0f, -10.0f); 
     barChart.titlePlotAreaFrameAnchor = CPTRectAnchorTop; 

     CPTXYAxisSet *axisSet = (CPTXYAxisSet *)barChart.axisSet; 
     CPTXYAxis *x = axisSet.xAxis; 
     x.axisLineStyle = nil; 
     x.majorTickLineStyle = nil; 
     x.minorTickLineStyle = nil; 
     x.majorIntervalLength = CPTDecimalFromString(@"10"); 
     x.orthogonalCoordinateDecimal = CPTDecimalFromString(@"0"); 
     x.title = @"Names"; 
     x.titleLocation = CPTDecimalFromFloat(7.5f); 
     x.titleOffset = 25.0f; 

     // Define some custom labels for the data elements 
     x.labelRotation = M_PI/5; 
     x.labelingPolicy = CPTAxisLabelingPolicyNone; 

     NSArray *customTickLocations = [NSArray arrayWithObjects:[NSDecimalNumber numberWithInt:0], [NSDecimalNumber numberWithInt:1], [NSDecimalNumber numberWithInt:2], [NSDecimalNumber numberWithInt:3], [NSDecimalNumber numberWithInt:4], nil]; 


     NSArray *xAxisLabels = [NSArray arrayWithObjects:@"a", @"b", @"c", @"d", @"e", nil]; 
     NSUInteger labelLocation = 0; 

     NSMutableArray *customLabels = [NSMutableArray arrayWithCapacity:[xAxisLabels count]]; 
     for (NSNumber *tickLocation in customTickLocations) 
     { 
      CPTAxisLabel *newLabel = [[CPTAxisLabel alloc] initWithText: [xAxisLabels objectAtIndex:labelLocation++] textStyle:x.labelTextStyle]; 
      newLabel.tickLocation = [tickLocation decimalValue]; 
      newLabel.offset = x.labelOffset + x.majorTickLength; 
      newLabel.rotation = M_PI/xAxisLength; 
      [customLabels addObject:newLabel]; 
     } 

     x.axisLabels = [NSSet setWithArray:customLabels]; 

     CPTXYAxis *y = axisSet.yAxis; 
     y.axisLineStyle = nil; 
     y.majorTickLineStyle = nil; 
     y.minorTickLineStyle = nil; 
     y.majorIntervalLength = CPTDecimalFromString(@"50"); 
     y.orthogonalCoordinateDecimal = CPTDecimalFromString(@"0"); 
     y.title = @"Work Status"; 
     y.titleOffset = 40.0f; 
     y.titleLocation = CPTDecimalFromFloat(150.0f); 

     CPTGraphHostingView *hostingView = [[CPTGraphHostingView alloc] initWithFrame:CGRectMake(0, 0, 320, 360)]; 
     hostingView.hostedGraph = barChart; 
     [self.view addSubview:hostingView]; 

     CPTXYPlotSpace *plotSpace = (CPTXYPlotSpace *) barChart.defaultPlotSpace; 
     plotSpace.xRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromDouble(0.0f) length:CPTDecimalFromDouble(16.0f)]; 
     plotSpace.yRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromDouble(0.0f) length:CPTDecimalFromDouble(500.0f)]; 

     CPTBarPlot *barPlot = [CPTBarPlot tubularBarPlotWithColor:[CPTColor blueColor] horizontalBars:NO]; 
     barPlot.plotRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromDouble(0.0) length:CPTDecimalFromDouble(10)];//xAxisLength 
     barPlot.barOffset = CPTDecimalFromFloat(0.25f); 
     barPlot.baseValue = CPTDecimalFromString(@"0"); 
     barPlot.barWidth = CPTDecimalFromFloat(10.0f); 
     barPlot.cornerRadius = 2.0f; 
     barPlot.dataSource = self; 
     [barChart addPlot:barPlot]; 
    } 

    -(void) getGraphValues 
    { 
     int barValues [] = {10,50,100,200};//,150,200,10,20,30,40,50,100,400,450,350 
     int barNums = sizeof(barValues)/sizeof(int); 

     samples = [[NSMutableArray alloc] initWithCapacity:barNums]; 

     for (int i = 0; i < 4; i++) 
     { 
      double x = i; 
      double y = barValues[i]; 
      NSLog(@"XVal : %@", X_VAL); 
      NSDictionary *sample = [NSDictionary dictionaryWithObjectsAndKeys: 
            [NSNumber numberWithDouble:30],X_VAL,[NSNumber numberWithDouble:y],Y_VAL,nil]; 
      [samples addObject:sample]; 
     } 
    } 


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

-(NSNumber *)numberForPlot:(CPTPlot *)plot field:(NSUInteger)fieldEnum recordIndex:(NSUInteger)index 
{ 
    NSDictionary *sample = [samples objectAtIndex:index]; 

    if (fieldEnum == CPTScatterPlotFieldX) 
     return [sample valueForKey:X_VAL]; 
    else 
     return [sample valueForKey:Y_VAL]; 
} 
+0

Bạn biết điều đó có nghĩa là thông báo lỗi, có đúng không? (Và gắn thêm ngăn xếp cuộc gọi tại thời điểm lỗi sẽ rất hữu ích trong việc chẩn đoán điều này.) –

Trả lời

17

Đảm bảo bạn đặt -all_load "cờ liên kết khác" trong cài đặt bản dựng. Cờ đó buộc hệ thống tải tất cả các phương thức danh mục như -sizeWithTextStyle:.

+0

Cảm ơn bạn đã trả lời – SampathKumar

+0

Xin lỗi để nói điều này, bạn có thể vui lòng tìm bất kỳ ví dụ nào cho số này – SampathKumar

+2

Bạn đã đọc [Core Plot wiki] (https://code.google.com/p/core-plot/wiki/UsingCorePlotInApplications)? –

10

Như Eric đã giải thích, bạn cần phải giữ cờ -all_load trong cài đặt bản dựng. Trong trường hợp bạn đang tự hỏi chính xác nơi này là có một cái nhìn vào hình ảnh này. Chúc may mắn!

Setting the all_add flag on XCode

+0

Đối với tất cả những người gặp sự cố tương tự như tôi đã định vị cài đặt trình liên kết, hãy đảm bảo cài đặt "Tất cả" được chọn thay vì cài đặt "Cơ bản" mặc định. Tôi ghét làm cho các tập tin. – Hampden123

Các vấn đề liên quan