Ios – How to animate the appearance of a bar chart in Core Plot


When first displaying a bar chart using Core Plot, I'd like the bars to grow upward until they reach their correct heights.

How would you create such an animation using this framework?

Best Solution

This is what I did:

  1. In my viewDidLoad controller's method I created the CPTXYGraph:

    graph = [[CPTXYGraph alloc] initWithFrame:self.view.bounds];
  2. I added animation to the empty graph:

    CAKeyframeAnimation *scale = [CAKeyframeAnimation animationWithKeyPath:@"transform"];
  3. Then in animationDidStop delegate's method I added the plot data and animation to the graph:

    CABasicAnimation *anim = [CABasicAnimation animationWithKeyPath:@"transform.scale.y"];
    [anim setDuration:2.0f];
    anim.toValue = [NSNumber numberWithFloat:1.0f];
    anim.fromValue = [NSNumber numberWithFloat:0.0f];
    anim.removedOnCompletion = NO;
    anim.delegate = self;
    anim.fillMode = kCAFillModeForwards;
    gPlot.anchorPoint = CGPointMake(0.0, 0.0);
    [gPlot addAnimation:anim forKey:@"grow"];
    [graph addPlot:gPlot ];// IMPORTANT here I added the plot data to the graph :) .
Related Question