Domanda

Is it possible to trigger when data provider of the flex chart changes ? Any ideas guys ? i used oncreation complete but it is not working when change data source of the chart dynamically.

È stato utile?

Soluzione

Try Changewatcher class.

import mx.binding.utils.ChangeWatcher;
import mx.events.PropertyChangeEvent;

ChangeWatcher.watch(this, "dataProvider", watchHandler);

private function watchHandler(e:PropertyChangeEvent):void
 {
                    // Do Something
 }

Otherwise try this, Add collection change listener to chart itself like below.

chart.addEventListener(CollectionEvent.COLLECTION_CHANGE, onChartDataProviderChange);

private function onChartDataProviderChange(e:CollectionEvent):void
     {
                        // Do Something
     }

if(condition1){
chart.dataprovider=provider1;
} 
if(condition2){
chart.dataprovider=provider2;
}

Hope it helps.

Altri suggerimenti

If the dataProvider is an ArrayCollection you can add a listener to the dataProvider object collection itself:

dataProvider.addEventListener(CollectionEvent.COLLECTION_CHANGE,listernerFunction);

Notice that if you replace the entire dataProvider object for example with the code

dataProvider  = null;
dataProvider = new ArrayCollection();

You will not trigger the event and you have to add a new listener to the new object.

Otherwise you can add listener to the chart itself that will be trigger every time the data provider object is replaced but it will not be trigger when the the collection itself changes.

chart.addEventListener(PropertyChangeEvent.PROPERTY_CHANGE,funct);
[..]
protected function funct( event:PropertyChangeEvent):void{
    if(event.property=="dataProvider"){
        //Your code
    }
}
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top