2 Replies Latest reply on May 26, 2009 2:14 PM by rcanulla

    How to update a chart when the array is updated

    rcanulla Level 1

      Hi I am using an array to populate a chart in FB3 and having trouble updating the chart when the array is updated.



               <mx:Label id="archiveTitle" x="10" y="10" text="Current Archive " fontSize="14" fontWeight="bold"/>
               <mx:PieChart id="chart" height="130" width="300" color="0x323232"
                  showDataTips="false" dataProvider="{ratingAC}"  y="22">
                      <mx:PieSeries field="Rating"/>


      Array + Vars

               public var newsDB:ArrayCollection = mx.core.Application.application.newsDB as ArrayCollection;
               private var positive:int = 1;
               private var neutral:int = 0;
               private var negative:int = 0;
               private var ratingAC:ArrayCollection = new ArrayCollection([
               { Rating: 1 },  // no data
               { Rating: positive }, // [0] positive
               { Rating: neutral }, // [1] neutral
               { Rating: negative }  // [2] negative
              private function init():void{
                     newsDB.addEventListener(CollectionEvent.COLLECTION_CHANGE, test);
                     newsDB.addEventListener(CollectionEvent.COLLECTION_CHANGE, buildChart);
              private function test(e:CollectionEvent):void{
                   trace("array changed");
                   positive = 20
              private function buildChart(e:CollectionEvent=null):void{
                   for(var i:int; i<newsDB.length; i++){
                        if(newsDB[i].rateItem == 0){
                             positive += 1;
                        if(newsDB[i].rateItem == 1){
                             neutral += 1;
                        if(newsDB[i].rateItem == 2){
                             negative += 1;
        • 1. Re: How to update a chart when the array is updated
          Brent Lamborn Level 2

          I'm not sure if I follow what is happening in your code but simply try re-setting the dataProvider in ActionScript. Sometimes that does the trick. So after the array is finished updating just  do:


          chart.dataProvider = ratingAC;

          1 person found this helpful
          • 2. Re: How to update a chart when the array is updated
            rcanulla Level 1

            Sorry, in my app I have an ArrayCollection of items from a news feed that the user has deemed important, and given each item a rating. The For loop will loop through the "newsDB" array and set the var accordingly (positive, negative, neutral). The variables are what is populating the arrayCollection (ratingAC). How would I either a) bind the variables to the ArrayCollection so that it updates when one has changed, or b) update the specific index in the array collection. When debugging, i notice that the variables are updating, but the arrayCollection is not.


            Thanks in advance!