2014-05-07 82 views
0
沒有看到折線圖的執行情況顯示

enter image description here線圖沒有正確的iOS

- (void)viewDidLoad 
{ 
    [super viewDidLoad]; 
PCLineChartView *chartLine=[[PCLineChartView alloc]initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height-30)]; 
     [chartLine setAutoresizingMask:UIViewAutoresizingFlexibleWidth| UIViewAutoresizingFlexibleHeight |UIViewAutoresizingFlexibleLeftMargin|UIViewAutoresizingFlexibleRightMargin]; 
    chartLine.minValue=0; 
    chartLine.maxValue=100; 
    [self.view addSubview:chartLine]; 

    NSError *error; 
    NSString *strFileContent = [NSString stringWithContentsOfFile:[[NSBundle mainBundle] 
                    pathForResource: @"sample_linechart_data" ofType: @"json"] encoding:NSUTF8StringEncoding error:&error]; 

    NSData *data = [strFileContent dataUsingEncoding:NSUTF8StringEncoding]; 
    NSArray *json = [NSJSONSerialization JSONObjectWithData:data options:0 error:nil]; 
     //NSLog(@"js:%@",json); 
    NSMutableArray *secondJson=[json valueForKeyPath:@"data"]; 
     //NSLog(@"sec js:%@",secondJson); 
    NSMutableArray *components=[NSMutableArray array]; 

    for (NSDictionary *graphInfo in secondJson) { 
     PCLineChartViewComponent *component=[[PCLineChartViewComponent alloc]init]; 
     [component setTitle:graphInfo[@"title"]]; 
     [component setPoints:graphInfo[@"data"]]; 
     [component setShouldLabelValues:NO]; 
     [component setColour:PCColorBlue]; 
     [components addObject:component]; 
    } 
    [chartLine setComponents:components]; 
    [chartLine setXLabels:[json valueForKeyPath:@"xLabels"]]; 
} 

回答

0

這很難說。要麼你有問題。或者你的數據設置不正確。你有更多的信息嗎?你能發佈其他信息嗎?

0

圖表顯示這是一個有點棘手,我有同樣的問題,以顯示正確的圖表我用這個代碼:

PCLineChartView *chart1 = [[PCLineChartView alloc] initWithFrame: /* Your frame */]; 
//For each component 
NSMutableArray *xLabels = [NSMutableArray array]; 
for (int i = 0; i<chart1.points.count; i++) { 
     [xLabels addObject:@""]; //If you don't wanna show a specific text, it's very importan that the quantity of xLabels array be the same than points array 
} 
chart1.xLabels = xLabels;