【发布时间】:2012-11-24 17:57:07
【问题描述】:
我有一个计时器,它正在更新我的 coreplot 数据以产生实时统计数据的错觉。当计时器触发时,它会向数组添加一个值并刷新散点图。这很好用,但是一旦我绘制了大约 10 个数据点,我想开始删除第一个点并只显示最后 10 个数据点。但是当我尝试删除一个点时,它会在彼此的顶部显示旧的和新的数据点。我不明白为什么会这样。我试图清除数组并重置它,但都无济于事。关于为什么会发生这种情况的任何想法。这是一些代码:
//START GRAPHING
self.count = 0;
if (numberOfPackets == 1){ //on the first packet
[self.repeatingTimer invalidate];
self.repeatingTimer = [NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(updateArray:) userInfo:nil repeats:YES];
self.arrayII = [[NSMutableArray alloc] init];
[self initPlot];
}
-(void) updateArray:(NSTimer *)timer{
self.count++;
// self.arrayII sources scatter plot data.
if (self.count < [dataPacketArray count]){
if (self.count > 5){
[self.arrayII removeObjectAtIndex:0]; //if I don't include this it works flawlessly.
}
[self.arrayII addObject:[dataPacketArray objectAtIndex:self.count]];
}
[self.view reloadInputViews];
[self configurePlots];
}
-(void) initPlot {
[self configureHost];
[self configureGraph];
[self configurePlots];
[self configureAxes];
}
我从this tutorial 获得了所有的初始情节。 非常感谢任何帮助。
【问题讨论】: