Search code examples
iosobjective-cxcode4core-plot

How to add animation to scatter graph using core plot?


I am using core plot library to display scatter chart in my app i display the scatter chart in my app from tutorial http://www.raywenderlich.com/13271/how-to-draw-graphs-with-core-plot-part-2 now i want that the user can see the animation of chart i-e frist the is drawn from 1st point to 2nd point after a small period of time than draw from 2nd to 3rd and so on and the user can see the animation.


Solution

  • There is currently no built-in support for this. You could use a timer to control the animation. Start with just the first data point in the plot. When the timer fires for the next animation frame, add the second point, but don't give it its final position. Instead, interpolate its position between the first point and its final position based on the time step. Move the second point at each time step until it reaches its final position. Add the third point on the next step. Continue this way until all points are shown at their final positions.

    Use the -insertDataAtIndex:numberOfRecords: method to add each point at the correct time. Use -reloadDataInIndexRange: to update the position of the last point. This will give better performance than the reloadData method which forces the plot to reload every data point each time.