6 Replies Latest reply on Jan 6, 2010 11:47 PM by LaVengeance

    problem with displaying xml data in line chart

    arunpad

      I have something like this xml data

       

      <data>
      <result month="Jan-04">
         
      <employee id="1">
             
      <a>81768</a>
             
      <b>60310</b>
             
      <c>43357</c>
         
      </employee>
         
      <employee id="2">
             
      <a>81768</a>
             
      <b>60310</b>
             
      <te>43357</c>
         
      </employee>
      </result>
      <result month="Feb-04">
         
      <employee id="1">
             
      <a>81156</a>
             
      <b>58883</b>
             
      <c>49280</c>
         
      </employee>
         
      <employee id="2">
             
      <a>81768</a>
             
      <b>60310</b>
             
      <c>43357</c>
         
      </employee>
      </result>

       

      I want to display it line chart with month on horizontal axis and a,b,c as series for employee with id==1. The following code doesnt display any data on the chart. Could someone point out the error?

       

       

      <mx:HTTPService id="srv" url="D:/data.xml" useProxy="false" result="myData=ArrayCollection(srv.lastResult.data.result)"/> 
      <mx:Panel title="Line Chart">
      <mx:LineChart id="myChart"
         
      showDataTips="true"
       
      enabled="true" dataProvider="{myData}">
         
      <mx:horizontalAxis>
            
      <mx:CategoryAxis categoryField="month"/>
         
      </mx:horizontalAxis>
         
      <mx:series>
            
      <mx:LineSeries yField="employee[0].a" displayName="A" name="a"/>
            
      <mx:LineSeries yField="employee[0].b" displayName="B" name="b"/>
            
      <mx:LineSeries yField="employee[0].c" displayName="C" name="c"/>
         
      </mx:series>
      </mx:LineChart>
      <mx:Legend dataProvider="{myChart}"/>    
        • 1. Re: problem with displaying xml data in line chart
          LaVengeance Level 1

          You need to send that HTTPRequest somewhere, best would be to add a creation complete handler to ur application tag and do a



          private function creationCompleteHandler():void{

          srv.send();

          }

           

          btw, if the XML is local, you need not use a HTTPRequest, you can do this :

           

           

          <mx:XML source="D:/data.xml"/>

           

           

          HTH !

          • 2. Re: problem with displaying xml data in line chart
            arunpad Level 1

            I added that as part of the application tag

             

            <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
                width="1035" height="681" creationComplete="srv.send()" activate="energize()" layout="absolute">

             

             

            I thought it was unrelated to the problem at hand- so only i did not include it in previous post..

            • 3. Re: problem with displaying xml data in line chart
              arunpad Level 1

              also using

              <mx:XML id="myData" source="D:/data.xml"/>

              instead of the httpservice doesnt solve the problem..

               

              Could use some help..

              • 4. Re: problem with displaying xml data in line chart
                LaVengeance Level 1

                Month is an attribute to a node, so you will have to access it using the '@' symbol :

                 

                 

                 <mx:CategoryAxis categoryField="@month"/>

                 

                 

                try making this change, if this doesn't help, pls post your entire code and the XML here...the current XML is
                not well formed, missing the </data> part..

                • 5. Re: problem with displaying xml data in line chart
                  arunpad Level 1

                  Sorry about the error in posting the xml.. my entire xml and entire code is below...

                   

                  <data>
                      <result month="Jan-04">
                          <employee id="1">
                              <itg>81768</itg>
                              <pe>60310</pe>
                              <te>43357</te>
                          </employee>
                          <employee id="2">
                              <itg>81768</itg>
                              <pe>60310</pe>
                              <te>43357</te>
                          </employee>
                      </result>
                      <result month="Feb-04">
                          <employee id="1">
                              <itg>81156</itg>
                              <pe>58883</pe>
                              <te>49280</te>
                          </employee>
                          <employee id="2">
                              <itg>81768</itg>
                              <pe>60310</pe>
                              <te>43357</te>
                          </employee>
                      </result>
                  </data>

                   

                  My entire code...

                   

                  <?xml version="1.0"?>
                  <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
                      width="1035" height="681" layout="absolute">
                    
                  <mx:XML id="myData" source="D:/data.xml"/>

                    <mx:Panel title="Line Chart" width="341" height="293" x="10" y="36">
                       <mx:LineChart id="myChart"
                          showDataTips="true"
                        enabled="true" dataProvider="{myData}" width="292" height="182">
                          <mx:horizontalAxis>
                             <mx:CategoryAxis categoryField="@month"/>
                          </mx:horizontalAxis>
                          <mx:series>
                             <mx:LineSeries yField="employee[0].itg" displayName="ITG" name="Itg"/>
                             <mx:LineSeries yField="employee[0].pe" displayName="PE" name="Pe"/>
                             <mx:LineSeries yField="employee[0].te" displayName="TE" name="Te"/>
                          </mx:series>
                       </mx:LineChart>
                       <mx:Legend dataProvider="{myChart}"/>    
                    </mx:Panel>  
                     
                  </mx:Application>

                   

                  No error is being reported but the chart does not display anything.

                  • 6. Re: problem with displaying xml data in line chart
                    LaVengeance Level 1

                    Your XML needs to be bindable. Use the [Bindable] attribute above your XML declaration, you may have to do this in AS..