2

我正在尝试使用核心图和绑定来绘制核心数据中的数据。我的核心数据模型:

在此处输入图像描述

我可以插入,所以我知道我的联系人很好......但这会在绑定处爆炸:

[<NSArrayController 0x6000001c40b0> valueForUndefinedKey:]: this class is not key value coding-compliant for the key measuredate.

-(void)addPlotWithIdentifier:(NSString *)identifier context:(NSManagedObjectContext *)moc
{

    CPTScatterPlot *newPlot = [[CPTScatterPlot alloc] initWithFrame:graph.bounds];
    dataSourceLinePlot.identifier     = identifier;



    CPTMutableLineStyle *lineStyle = [dataSourceLinePlot.dataLineStyle mutableCopy];
    lineStyle.lineWidth              = 2.0;
    lineStyle.lineColor              = [CPTColor greenColor];
    dataSourceLinePlot.dataLineStyle = lineStyle;


    CPTXYPlotSpace *plotSpace = (CPTXYPlotSpace *)graph.defaultPlotSpace;
    plotSpace.xRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromFloat(1380243600)
                                                    length:CPTDecimalFromFloat(1382835600)];
    plotSpace.yRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromFloat(0)
                                                     length:CPTDecimalFromFloat(100)];

    [dataSourceLinePlot setPlotSpace:plotSpace];
    NSLog(@"Create a controller");
    NSArrayController *newController=[[NSArrayController alloc] initWithContent:nil];
    NSLog(@"MOC: set context");
    [newController setManagedObjectContext:moc];
    NSLog(@"MOC: set Entity");
    [newController setEntityName:@"BM_Measure"];
    NSLog(@"MOC: set Editable");
    [newController setEditable:FALSE];
    NSLog(@"MOC: set sort descriptors");
    [newController setSortDescriptors:[NSArray arrayWithObject:[NSSortDescriptor sortDescriptorWithKey:@"measuredate" ascending:YES]]];
    NSLog(@"MOC: fetch");

    [newController setAutomaticallyPreparesContent:TRUE];
    [newController setAutomaticallyRearrangesObjects:TRUE];
    NSError *error;
    if ([newController  fetchWithRequest:nil merge:NO error:&error] == NO){
        NSLog(@"Couldnt fetch");
    }
    NSLog(@"%@",newController);

    NSLog(@"Bind x");
    [newPlot bind:CPTScatterPlotBindingXValues toObject:newController withKeyPath:@"measuredate" options:nil];
    NSLog(@"Bind y");
    [newPlot bind:CPTScatterPlotBindingYValues toObject:newController withKeyPath:@"measurevalue" options:nil];
    NSLog(@"Save Objects");

    [g_Plots addObject:newPlot];
    [g_ArrayControllers addObject:newController];
    [graph addPlot:newPlot];
    NSLog(@"Added... %ld",[g_Plots count]);



}
4

1 回答 1

0

Core Plot 绑定需要数据数组。这是来自CPTTestApp示例应用程序的绑定代码:

[boundLinePlot bind:CPTScatterPlotBindingXValues
           toObject:self 
        withKeyPath:@"arrangedObjects.x"
            options:nil];
[boundLinePlot bind:CPTScatterPlotBindingYValues
           toObject:self
        withKeyPath:@"arrangedObjects.y"
            options:nil];
于 2013-10-24T23:07:46.437 回答