Mino
Mino

Reputation: 941

Animating a LineChart based on changing dataProvider

I need to be able to animate a LineChart based on the SeriesInterpolate data effect (I will have an Array of dataproiders). I want to have a "Play" button that will:

  1. initialize the LineChart with the first dataprovider in the array
  2. start the animation and wait for the animation to finish before loading the second data provider
  3. repeat the process until all data providers in the Array are loaded

Any thoughts?

Upvotes: 0

Views: 665

Answers (1)

Nate
Nate

Reputation: 2881

No problem, you're just going to use the effectEnd event

So on your effect, you'll want to attach the effectEnd listener, something like this :

<mx:SeriesInterpolate id="interpolateIn" duration="1000" effectEnd="fetchNextDataset()"/> 

Then in your code, you need to store your datasets, and an index of which you're currently viewing, and finally the method that switches them.

        private var datasets        :ArrayCollection;   // fill with your datasets              
        private var currentDataset  : uint = 0;         // holds current dataset

        private function fetchNextDataset () : void {
            if( currentDataset >= datasets.length) return;  // out of range, played em all!
            candlestickchart.dataProvider = datasets.getItemAt(currentDataset);
            currentDataset++;
        }

As far as the play button, all it needs to do is make the first call to fetchNextDataset();

<mx:Button label="play" click="fetchNextDataset()"/>

Make sense?

Upvotes: 2

Related Questions