NSMutableArray 不在图表上显示数据

NSMutableArray Not Displaying Data On Chart

我正在尝试使用 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];

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];
    }];
}

试试这个。您应该始终在获取数据后重新加载 table。您正在后台线程上检索数据,因此您应该在获取信息后重新加载 table, 在 for 循环之后和块内部 .