2 Replies Latest reply on Jun 9, 2010 9:10 AM by asifdegr8

    Problem in Line graph

    asifdegr8 Level 1

      <?xml version="1.0" encoding="utf-8"?>
      <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">
          <mx:Script>
              <![CDATA[
                  import mx.collections.ArrayCollection;
                 
                   [Bindable]
                  var xmlProducts:XMLList = graphList;       

       


           [Bindable]
           public var products:ArrayCollection = new ArrayCollection([
              {unit:"Radio", year:2007, quantity:5},
              {unit:"Radio", year:2008, quantity:7},
              {unit:"Radio", year:2009, quantity:10}
           ]);

       

              ]]>
          </mx:Script>
         
          <mx:XMLList xmlns="" id="graphList">
              <record>
                  <unit>Radio</unit>
                  <year>2007</year>
                  <quantity>5</quantity>
              </record>
              <record>
                  <unit>Radio</unit>
                  <year>2008</year>
                  <quantity>7</quantity>
              </record>
              <record>
                  <unit>Radio</unit>
                  <year>2009</year>
                  <quantity>10</quantity>
              </record>
          </mx:XMLList>

       


          <mx:LineChart x="386" y="23" id="unitChart" height="199" dataProvider="{products}" showDataTips="true">
             
              <mx:horizontalAxis>
                  <mx:CategoryAxis dataProvider="{products}" categoryField="year" />
              </mx:horizontalAxis>
             
              <mx:series>
                  <mx:LineSeries  yField="quantity"  displayName="Quantity" />
              </mx:series>
          </mx:LineChart>
          <mx:Legend dataProvider="{products}"/>
      </mx:Application>

       

       

       

      1- I have to draw a line chart for the products based on XMLList as dataprovider. In which horizontal axis is based on year values i.e 2007, 2008 , 2009. Vertical axis showing quantity for each unit data item Radio.

       

      2- When i make a graph based on arraylist as data provider it works fine as in given example. but when i use xmlList as data provider it shows nothing. I think values in XMLList are all text but i don't know how to convert them to numeric.

        • 1. Re: Problem in Line graph
          BhaskerChari Level 4

          Hi Asif,

           

          You need to modify Your XmlList structure and you need to give XMLListCollection as a dataprovider to the LineGraph.

           

          See the working sample below:

           

          <?xml version="1.0" encoding="utf-8"?>
          <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">
              <mx:Script>
                  <![CDATA[
                      import mx.collections.ArrayCollection;

               [Bindable]
               public var products:ArrayCollection = new ArrayCollection([
                  {unit:"Radio", year:2007, quantity:5},
                  {unit:"Radio", year:2008, quantity:7},
                  {unit:"Radio", year:2009, quantity:10}
               ]);


                  ]]>
              </mx:Script>
             
              <!--<mx:XMLList xmlns="" id="graphList">
                  <record>
                      <unit>Radio</unit>
                      <year>2007</year>
                      <quantity>5</quantity>
                  </record>
                  <record>
                      <unit>Radio</unit>
                      <year>2008</year>
                      <quantity>7</quantity>
                  </record>
                  <record>
                      <unit>Radio</unit>
                      <year>2009</year>
                      <quantity>10</quantity>
                  </record>
              </mx:XMLList>-->
             
              <mx:XMLListCollection id="graphList">
                  <mx:source>
                      <mx:XMLList>
                          <record unit="Radio" year="2007" quantity="5" />
                          <record unit="Radio" year="2008" quantity="7" />
                          <record unit="Radio" year="2009" quantity="10" />               
                      </mx:XMLList>
                  </mx:source>
              </mx:XMLListCollection>

              <mx:LineChart x="386" y="23" id="unitChart" height="199" dataProvider="{graphList}" showDataTips="true">
                 
                  <mx:horizontalAxis>
                      <mx:CategoryAxis categoryField="@year" title="Year"/>
                  </mx:horizontalAxis>
                  <mx:verticalAxis>
                      <mx:LinearAxis baseAtZero="false" title="Quantity" />
                  </mx:verticalAxis>
                  <mx:series>
                      <mx:LineSeries  yField="@quantity"  displayName="Quantity"/>
                  </mx:series>
              </mx:LineChart>
              <mx:Legend dataProvider="{unitChart}"/>
          </mx:Application>

          If this post answers your question or helps, please kindly mark it as such.


          Thanks,

          Bhasker Chari

          • 2. Re: Problem in Line graph
            asifdegr8 Level 1

            Thanks once again ... my problem solved for the base case that just shows the quantities for Radio only.

             

            Let's suppose my xmlList is

                        <mx:XMLList>
                            <record unit="Radio" year="2007" quantity="5" />
                            <record unit="Radio" year="2008" quantity="7" />
                            <record unit="Radio" year="2009" quantity="10" />               

                            <record unit="Television" year="2007" quantity="3" />
                            <record unit="Television" year="2008" quantity="12" />
                            <record unit="Television" year="2009" quantity="8" />               

                            <record unit="Computer" year="2007" quantity="9" />
                            <record unit="Computer" year="2008" quantity="4" />
                            <record unit="Computer" year="2009" quantity="10" />               
                        </mx:XMLList>

             

            I have to draw 3 lines one for each unit Radio, Television and Computer showing their quantities in each year. I am getting XMLList from HttpService in e4x format.