4
votes

I have a scatter Graph in my iPad app using Core Plot, and all is working well. What I want to do is animate the drawing of the line so that it looks like each point to point on the graph is being drawn in front of the user. I'm not looking to fade the line in as I have already got this working.

I have seen the question asked below which is very similar, but I don't fully understand the answer. Core-Plot - animating a CPScatterPlot

Please bare in mind I am new to Core Plot and have only been using it for a day or so.

Thanks

2
How did you manage to fade the single "chunk" of the line? - Fabiano Francesconi

2 Answers

3
votes
self.plot.anchorPoint = CGPointMake(0.0, 0.0); // Moved anchor point, 

CABasicAnimation *scaling = [CABasicAnimation 
                                 animationWithKeyPath:@"transform.scale.y"]; // s
scaling.fromValue = [NSNumber numberWithFloat:0.0]; 
scaling.toValue = [NSNumber numberWithFloat:1.0]; 
scaling.duration = 0.1f; // Duration 
scaling.removedOnCompletion = NO; 
scaling.fillMode = kCAFillModeForwards; 
[self.plot addAnimation:scaling forKey:@"scaling"];
1
votes

Look at the "real time demo" plot in the Plot Gallery example app included with Core Plot. It uses a timer to add points to a scatter plot one at a time. The code can be found here.

The -newData: method adds a point to the plot and updates the plot range so the new point will be visible. The call to -insertDataAtIndex:numberOfRecords: causes the plot to retrieve the new data point and redraw automatically.