- (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)
如果没有看到折线图的实施,很难说。要么你有问题。或者您的数据设置不正确。你有进一步的信息吗?你能发布更多信息吗?
答案 1 :(得分: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;