我正在尝试使用JBChartView和Objective C在图表上显示数据。当我尝试将数据从我的NSDictionary加载到在我的图表上显示数据的数组时,没有显示任何数据。但是,当我放置虚拟数据时,它会显示,这是我的NSDictionary之间的问题。我的词典中有信息,我可以证实这一点。这是我的代码:
NSMutableArray *mutableChartData = [NSMutableArray array];
if([PFUser currentUser]){
PFQuery *query = [PFQuery queryWithClassName:@"Hours"];
[query whereKey:@"user" equalTo:[PFUser currentUser]];
[query findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {
for (PFObject *object in objects) {
[mutableChartData addObject:object[@"Jan"]];
[mutableChartData addObject:object[@"Feb"]];
[mutableChartData addObject:object[@"Mar"]];
[mutableChartData addObject:object[@"Apr"]];
[mutableChartData addObject:object[@"May"]];
[mutableChartData addObject:object[@"Jun"]];
[mutableChartData addObject:object[@"Jul"]];
[mutableChartData addObject:object[@"Aug"]];
[mutableChartData addObject:object[@"Sep"]];
[mutableChartData addObject:object[@"Oct"]];
[mutableChartData addObject:object[@"Nov"]];
[mutableChartData addObject:object[@"Dec"]];
}
}];
}
_chartData = [NSArray arrayWithArray:mutableChartData];
_monthlySymbols = [[[NSDateFormatter alloc] init] shortMonthSymbols];
[self.barChartView reloadData];
答案 0 :(得分:2)
NSMutableArray *mutableChartData = [NSMutableArray array];
if([PFUser currentUser]){
PFQuery *query = [PFQuery queryWithClassName:@"Hours"];
[query whereKey:@"user" equalTo:[PFUser currentUser]];
[query findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {
for (PFObject *object in objects) {
[mutableChartData addObject:object[@"Jan"]];
[mutableChartData addObject:object[@"Feb"]];
[mutableChartData addObject:object[@"Mar"]];
[mutableChartData addObject:object[@"Apr"]];
[mutableChartData addObject:object[@"May"]];
[mutableChartData addObject:object[@"Jun"]];
[mutableChartData addObject:object[@"Jul"]];
[mutableChartData addObject:object[@"Aug"]];
[mutableChartData addObject:object[@"Sep"]];
[mutableChartData addObject:object[@"Oct"]];
[mutableChartData addObject:object[@"Nov"]];
[mutableChartData addObject:object[@"Dec"]];
}
_chartData = [NSArray arrayWithArray:mutableChartData];
_monthlySymbols = [[[NSDateFormatter alloc] init] shortMonthSymbols];
[self.barChartView reloadData];
}];
}
试试这个。您应该在获取数据后始终重新加载表。您正在后台线程中检索数据,因此您应该在获取信息后重新加载表格,在for循环之后和块内部。