0
votes

I have a timer that is updating my coreplot data to give the illusion of real time stats. When the timer fires it adds a value to an array and refreshes the scatter plot. This works great, however once I graph about 10 data points I want to start removing the first points and only displaying the last 10 datapoints. But when I try to remove data a point it displays the old and the new datapoints on top of eachother. I can't figure out why this would be. I have tried to nil out the array and reset it and all to no avail. Any ideas on why this would be happening. Here is some code:

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

I got all the init plot stuff from this tutorial. Any help is greatly appreciated.

2

2 Answers

0
votes

I figured out that it is not the array that is throwing everything off. The scatter plot is not removing the previous plots but it is just adding plots. It looks like it's the same plot because it is just adding points and regraphing it on top of the old ones. As soon as you remove a point then then they don't line up. Then next question is how do you nil out the old plots...

0
votes

I assume the -configurePlots method is the one that adds the plot to the graph. Don't call that method each time the data changes. Use the -reloadData method on the plot to force it to reload all of its data.

The "Real-Time Plot" in the Plot Gallery example app shows a better way to update the data like this. It removes the expired data points and adds only the new data rather than reloading everything on each update. With only 10 data points, it might not matter, but if you have a larger data array, updating only the changed data can improve performance.