0
我想要動態地在x軸上從右向左移動coreplot圖形。將核心繪圖從右向左移動
例如,在覈心PLot圖庫示例中,圖形從左向右移動。對於我使用的代碼:
NSTimer *dataTimer = [NSTimer timerWithTimeInterval:1.0
target:self
selector:@selector(newData:)
userInfo:nil
repeats:YES];
[[NSRunLoop mainRunLoop] addTimer:dataTimer forMode:NSDefaultRunLoopMode];
-(void)newData:(NSTimer *)theTimer
{
CPTPlot *thePlot = [[self getCorePLotGraph] plotWithIdentifier:@"Device1"];
CPTXYPlotSpace *plotSpace = (CPTXYPlotSpace *)[self getCorePLotGraph].defaultPlotSpace;
NSUInteger location = (currentIndex >= kMaxDataPoints ? currentIndex - kMaxDataPoints + 2 : 0);
CPTPlotRange *newRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromUnsignedInteger(location)
length:CPTDecimalFromUnsignedInteger(kMaxDataPoints-2)];
**CPTMutablePlotRange *xRange = [[self getCoreplotSpace].xRange mutableCopy];
[xRange expandRangeByFactor:CPTDecimalFromCGFloat(-2.0)];
[self getCoreplotSpace].xRange = xRange;**
[CPTAnimation animate:plotSpace
property:@"xRange"
fromPlotRange:plotSpace.xRange
toPlotRange:newRange
duration:CPTFloat(1.0/kFrameRate)];
currentIndex++;
[temperatureValuesArray addObject:[NSNumber numberWithDouble:(1.0 - kAlpha) * [[temperatureValuesArray lastObject] doubleValue] + kAlpha * rand()/(double)RAND_MAX]];
[thePlot insertDataAtIndex:temperatureValuesArray.count - 1 numberOfRecords:1];
}
在上面的代碼中,大膽的代碼是從從右向左移動了什麼我現在嘗試。
但它不是從右向左移動。你能幫我怎麼做。
感謝
'plotSpace.xRange = newRange;'有什麼問題? –
我想從右向左移動X軸,這就是爲什麼我使用了這樣的代碼。我是這個核心情節的新手。我以這種方式嘗試過。請糾正我 – Dhanunjaya