2016-06-29 7 views
0

core-plotからiosプロジェクトにリアルタイムプロットのサンプルを実装しようとしていますが、[CPTPlotRange objCType]: unrecognized selector sent to instanceはグラフを移動するCPTAnimationを停止しているようです最新の値。[CPTPlotRange objCType]:インスタンスに送信されたセレクタが認識されない

これは、ほとんどすべての私のコードのであり、この問題は

-(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

どの回線がクラッシュしますか? – dan

+0

クラッシュしません。データ量がkMaxDataPointsに達すると、認識できないセレクタエラーが送信され続けます。 – insertawordhere

答えて

0

プロット範囲をアニメーション化する場合、このエラーの原因となったコアプロット2.1のバグがありましたが発生した理由を私は理解することはできません。マスターブランチで修正され、次のリリースになります。

その間に、リリースパッケージ(pod 'CorePlot', :git => 'https://github.com/core-plot/core-plot.git')ではなく最新のコードをGitHubから、またはココアポスを最新のコードmasterに変更することができます。

関連する問題