Animate Pie Chart slices using Core Plot

726 views Asked by At

I am creating a pie chart using Core Plot. I need to add animation to it so that the slices grow from 0 to 360 degrees. I am using the following method to animate:

-(void)animatePlot:(CPTPlot *)pPlot
          animated:(BOOL)bAnimated
{
  [[CPTAnimation sharedInstance] removeAllAnimationOperations];

    if (bAnimated) {

        CPTPieChart *pPieChart = (CPTPieChart *)pPlot;
        [CPTAnimation animate:pPieChart
                     property:@"startAngle"
                         from:0
                           to:M_PI*2
                     duration:5];

    }

There are 2 problems: 1. The last slice of the pie chart does animate fully at times. SO I get an incomplete slice after the animation has ended. 2. The data labels for the slices indicate values that are actually at the opposite end of the pie's diameter (180 degrees apart)

How can I get rid of the aforementioned problems and animate the pie chart properly? I do not want the entire pie chart to rotate. I just need the slices to grow from 0 to their respective sizes.

2nd EDIT

I figured out the problem. Using the following code now:

CPTPieChart *pPieChart = (CPTPieChart *)pPlot;

        pPieChart.startAngle = M_PI;

        [CPTAnimation animate:pPieChart
                     property:@"endAngle"
                         from:-M_PI
                           to:M_PI
                     duration:0.5];

The chart animates from 180 degrees. This resolves the data label issue. However I am still getting the first issue that the last slice does not animate fully. I have noticed that it is more apparent when the animation duration is short. Following is the screenshot. Here is where the animation stops:

enter image description here

1

There are 1 answers

1
Eric Skroch On

To make the pie chart grow, animate the endAngle.

I tried this animation in the Plot Gallery example app and I didn't see any problems with the labels. Can you post a picture?