2 Replies Latest reply on May 31, 2010 10:18 PM by Dajji

    Line series Array Collection

    194642537 Level 1

      Hi i am building a line chart.

       

       

      public var expenses:ArrayCollection = new ArrayCollection([
              {Month:"Jan", Profit:2000, Expenses:1500, Amount:450},
              {Month:"Feb", Profit:1000, Expenses:200, Amount:600},
              {Month:"Mar", Profit:1500, Expenses:500, Amount:300}
           ]);

       

       

      In my case i do not know what will be the names (in this case Month , Profit )

       

      So how do i build me arraycollection without know the labels

       

      Thanks

        • 1. Re: Line series Array Collection
          BhaskerChari Level 4

          Hi,

          Is your problem is about how to populate the ArrayCollection or about assigning the datafields to the LineSeries...dynamically?

           

           

          Thanks,

          Bhasker Chari

          • 2. Re: Line series Array Collection
            Dajji Level 3

            How will you get the data for your chart? Is it going to be an xml? With this assumption, I am quoting an example with xml here.

             

            Suppose you get the following xml.

             

            var x:XML = new XML(<root>
                 <items>
                      <item meta="month">Jan</item>
                      <item meta="profit">2000</item>
                      <item meta="expenses">1500</item>
                      <item meta="amount">450</item>
                 </items>
                 <items>
                      <item meta="month">Feb</item>
                      <item meta="profit">1000</item>
                      <item meta="expenses">200</item>
                      <item meta="amount">600</item>
                 </items>
            </root>);
            

             

            Now you need to convert this to ArrayCollection.

             

            public var expenses:ArrayCollection = new ArrayCollection();
            
            for each(var items:XML in x.children()){
                 var obj:Object = new Object();
            
                 for each(var item:XML in items.children()){
                      obj[item.meta] = item.text();
                 }
            
                 expenses.addItem(obj);
            }