gpt4 book ai didi

ios - 从右向左移动 core plot 图

转载 作者:行者123 更新时间:2023-11-29 02:47:28 25 4
gpt4 key购买 nike

我想在 x 轴上从右向左动态移动核心图。

例如,在核心 PLot Gallery 示例中,图形从左向右移动。为此,我正在使用代码:

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];
}

在上面的代码中,粗体代码用于从右向左移动我现在尝试的内容。

但它并没有从右向左移动。你能帮我看看怎么做吗?

谢谢

最佳答案

您似乎从 "Real Time Plot" demo 中复制了代码包含在 Core Plot 中(复制如下)。这按照您的描述工作:

-(void)newData:(NSTimer *)theTimer
{
CPTGraph *theGraph = (self.graphs)[0];
CPTPlot *thePlot = [theGraph plotWithIdentifier:kPlotIdentifier];

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

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

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

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

currentIndex++;
[plotData addObject:@( (1.0 - kAlpha) * [[plotData lastObject] doubleValue] + kAlpha * rand() / (double)RAND_MAX )];
[thePlot insertDataAtIndex:plotData.count - 1 numberOfRecords:1];
}
}

您根本不需要在此方法中更新 xRange — 动画会处理这些。

关于ios - 从右向左移动 core plot 图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24932166/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com