2016-06-29 7 views
0

Ich versuche das Echtzeitplot-Beispiel von Core-Plot in mein iOS-Projekt zu implementieren, ich bekomme immer [CPTPlotRange objCType]: unrecognized selector sent to instance, was die CPTAnimation zum Verschieben des Graphen zu stoppen scheint die neuesten Werte.[CPTPlotRange objCType]: unerkannter Selektor an Instanz gesendet

Das ist so ziemlich alle meine Code, und ich kann dieses Problem nicht herausfinden, warum tritt

-(id)initWithGraphView:(CPTGraphHostingView *) gView name:(NSString *)label { 
    self = [super init]; 

    if(self) { 
     _graphView = gView; 
     CGRect bounds = _graphView.bounds; 
     _graph = [[CPTXYGraph alloc] initWithFrame:bounds]; 
     _graphView.hostedGraph = _graph; 
     _currentIndex = 0; 
     _plotData = [[NSMutableArray alloc] initWithCapacity:kMaxDataPoints]; 
     [_plotData removeAllObjects]; 


     CPTMutableLineStyle *majorGridLineStyle = [CPTMutableLineStyle lineStyle]; 
     majorGridLineStyle.lineWidth = 0.75; 
     majorGridLineStyle.lineColor = [[CPTColor colorWithGenericGray:CPTFloat(0.2)] colorWithAlphaComponent:CPTFloat(0.75)]; 

     CPTMutableLineStyle *minorGridLineStyle = [CPTMutableLineStyle lineStyle]; 
     minorGridLineStyle.lineWidth = 0.25; 
     minorGridLineStyle.lineColor = [[CPTColor whiteColor] colorWithAlphaComponent:CPTFloat(0.1)]; 

     // Axes 
     // X axis 
     CPTXYAxisSet *axisSet = (CPTXYAxisSet *)_graph.axisSet; 
     CPTXYAxis *x   = axisSet.xAxis; 
     x.labelingPolicy  = CPTAxisLabelingPolicyAutomatic; 
     x.orthogonalPosition = @0.0; 
     x.majorGridLineStyle = majorGridLineStyle; 
     x.minorGridLineStyle = minorGridLineStyle; 
     x.minorTicksPerInterval = 9; 
     x.title     = @"X Axis"; 

     NSNumberFormatter *labelFormatter = [[NSNumberFormatter alloc] init]; 
     labelFormatter.numberStyle = NSNumberFormatterNoStyle; 
     x.labelFormatter   = labelFormatter; 

     // Y axis 
     CPTXYAxis *y = axisSet.yAxis; 
     y.labelingPolicy  = CPTAxisLabelingPolicyAutomatic; 
     y.orthogonalPosition = @0.0; 
     y.majorGridLineStyle = majorGridLineStyle; 
     y.minorGridLineStyle = minorGridLineStyle; 
     y.minorTicksPerInterval = 3; 
     y.title     = @"Y Axis"; 
     y.axisConstraints  = [CPTConstraints constraintWithLowerOffset:0.0]; 

     // Rotate the labels by 45 degrees, just to show it can be done. 
     x.labelRotation = CPTFloat(M_PI_4); 

     // Create the plot 
     CPTScatterPlot *dataSourceLinePlot = [[CPTScatterPlot alloc] init]; 
     dataSourceLinePlot.identifier  = kPlotIdentifier; 
     dataSourceLinePlot.cachePrecision = CPTPlotCachePrecisionDouble; 
     dataSourceLinePlot.interpolation = CPTScatterPlotInterpolationCurved; 

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

     dataSourceLinePlot.dataSource = self; 
     [_graph addPlot:dataSourceLinePlot]; 

     // Plot space 
     CPTXYPlotSpace *plotSpace = (CPTXYPlotSpace *)_graph.defaultPlotSpace; 
     plotSpace.xRange = [CPTPlotRange plotRangeWithLocation:@0.0 length:@(kMaxDataPoints - 2)]; 
     plotSpace.yRange = [CPTPlotRange plotRangeWithLocation:@0.0 length:@1000000.0]; 

    } 

    return self; 
} 

-(void)newData:(int)value 
{ 
    NSLog(@"adding, %i", value); 
    CPTGraph *theGraph = _graph; 
    CPTPlot *thePlot = [theGraph plotWithIdentifier:kPlotIdentifier]; 

    if (thePlot) { 
     if (self.plotData.count >= kMaxDataPoints) { 
      [self.plotData removeObjectAtIndex:0]; 
      [thePlot deleteDataInIndexRange:NSMakeRange(0, 1)]; 
     } 

     CPTXYPlotSpace *plotSpace = (CPTXYPlotSpace *)_graph.defaultPlotSpace; 
     NSUInteger location  = (self.currentIndex >= kMaxDataPoints ? self.currentIndex - kMaxDataPoints + 2 : 0); 

     CPTPlotRange *oldRange = [CPTPlotRange plotRangeWithLocation:@((location > 0) ? (location - 1) : 0) 
                   length:@(kMaxDataPoints - 2)]; 
     CPTPlotRange *newRange = [CPTPlotRange plotRangeWithLocation:@(location) 
                   length:@(kMaxDataPoints - 2)]; 

     [CPTAnimation animate:plotSpace 
        property:@"xRange" 
       fromPlotRange:oldRange 
        toPlotRange:newRange 
        duration:CPTFloat(1.0/kFrameRate)]; 

     self.currentIndex++; 
     [self.plotData addObject:@(value)]; 
     [thePlot insertDataAtIndex:self.plotData.count - 1 numberOfRecords:1]; 
    } 
} 

-(NSUInteger)numberOfRecordsForPlot:(nonnull CPTPlot *)plot 
{ 
    return _plotData.count; 
} 

-(nullable id)numberForPlot:(nonnull CPTPlot *)plot field:(NSUInteger)fieldEnum recordIndex:(NSUInteger)index 
{ 
    NSNumber *num = nil; 

    switch (fieldEnum) { 
     case CPTScatterPlotFieldX: 
      num = @(index + _currentIndex - _plotData.count); 
      break; 

     case CPTScatterPlotFieldY: 
      num = _plotData[index]; 
      break; 

     default: 
      break; 
    } 

    return num; 
} 
+0

In welcher Zeile stürzt es ab? – dan

+0

Es stürzt nicht ab, es sendet weiterhin den nicht erkannten Selektorfehler, nachdem die Datenmenge kMaxDataPoints erreicht hat. – insertawordhere

Antwort

0

Es gibt einen Bug in Core-Plot 2.1 war, die diesen Fehler verursacht, wenn Animieren Grundstück liegt. Es ist auf den Master-Zweig festgelegt und wird in der nächsten Version sein.

In der Zwischenzeit können Sie den neuesten Code von GitHub abrufen oder Cocoapods auf den neuesten Code auf master anstatt auf ein Release-Paket (pod 'CorePlot', :git => 'https://github.com/core-plot/core-plot.git') verweisen.

Verwandte Themen