我试图将核心情节中的实时情节示例实施到我的ios项目中,我不断得到[CPTPlotRange objCType]: unrecognized selector sent to instance
这似乎停止CPTAnimation以将图形移动到最新值。
这几乎是我的所有代码,我无法弄清楚为什么会出现这个问题
-(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 :(得分:0)
Core Plot 2.1中存在一个错误,在动画绘制范围时会导致此错误。它已在主分支上修复,并将在下一个版本中。
与此同时,您可以从GitHub提取最新代码或将Cocoapods指向master
上的最新代码,而不是发布包(pod 'CorePlot', :git => 'https://github.com/core-plot/core-plot.git'
)。