2 Replies Latest reply on Aug 18, 2009 5:42 AM by Sen Imagines

    external XML data for plot chart

    Sen Imagines Level 1

      Hi,

       

      Can you provide the XML equivalent & the corresponding changes to be done in the below plot chart code :

       

      <?xml version="1.0"?>
      <!-- charts/BasicPlot.mxml -->
      <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml">
        <mx:Script><![CDATA[
           import mx.collections.ArrayCollection;
      
           [Bindable]
           public var expenses:ArrayCollection = new ArrayCollection([
              {Month:"January", Profit:2000, Expenses:1500, Amount:450},
              {Month:"February", Profit:1000, Expenses:200, Amount:600},
              {Month:"March", Profit:1500, Expenses:500, Amount:300},
              {Month:"April", Profit:500, Expenses:300, Amount:500},
              {Month:"May", Profit:1000, Expenses:450, Amount:250},
              {Month:"June", Profit:2000, Expenses:500, Amount:700}
           ]);
        ]]></mx:Script>
        <mx:Panel title="Plot Chart">
           <mx:PlotChart id="myChart" dataProvider="{expenses}"
           showDataTips="true">
              <mx:series>
                 <mx:PlotSeries
                      xField="Expenses"
                      yField="Profit"
                      displayName="Plot 1"
                 />
                 <mx:PlotSeries
                      xField="Amount"
                      yField="Expenses"
                      displayName="Plot 2"
                 />
                 <mx:PlotSeries
                      xField="Profit"
                      yField="Amount"
                      displayName="Plot 3"
                 />
              </mx:series>
           </mx:PlotChart>
           <mx:Legend dataProvider="{myChart}"/>
        </mx:Panel>
      </mx:Application>
      
        • 1. Re: external XML data for plot chart
          Gregory Lafrance Level 6

          This does what you want.

           

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

           

          <?xml version="1.0"?>
          <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
            creationComplete="init();">
            <mx:Script>
              <![CDATA[
                import mx.collections.XMLListCollection;
          
                [Bindable] public var expenses:XMLListCollection;
                
                private function init():void{
                  expenses = new XMLListCollection(XMLList(xml..dataItem));
                }
               
                private var xml:XML = 
                  <data>
                    <dataItem>
                      <Month>January</Month>
                      <Profit>2000</Profit>
                      <Expenses>1500</Expenses>
                      <Amount>450</Amount>
                    </dataItem>
                    <dataItem>
                      <Month>February</Month>
                      <Profit>1000</Profit>
                      <Expenses>200</Expenses>
                      <Amount>600</Amount>
                    </dataItem>
                    <dataItem>
                      <Month>March</Month>
                      <Profit>1500</Profit>
                      <Expenses>500</Expenses>
                      <Amount>300</Amount>
                    </dataItem>
                    <dataItem>
                      <Month>April</Month>
                      <Profit>500</Profit>
                      <Expenses>300</Expenses>
                      <Amount>500</Amount>
                    </dataItem>
                    <dataItem>
                      <Month>May</Month>
                      <Profit>1000</Profit>
                      <Expenses>450</Expenses>
                      <Amount>250</Amount>
                    </dataItem>
                    <dataItem>
                      <Month>June</Month>
                      <Profit>2000</Profit>
                      <Expenses>500</Expenses>
                      <Amount>700</Amount>
                    </dataItem>
                  </data>;
            ]]></mx:Script>
            <mx:Panel title="Plot Chart">
               <mx:PlotChart id="myChart" dataProvider="{expenses}"
               showDataTips="true">
                  <mx:series>
                     <mx:PlotSeries
                          xField="Expenses"
                          yField="Profit"
                          displayName="Plot 1"
                     />
                     <mx:PlotSeries
                          xField="Amount"
                          yField="Expenses"
                          displayName="Plot 2"
                     />
                     <mx:PlotSeries
                          xField="Profit"
                          yField="Amount"
                          displayName="Plot 3"
                     />
                  </mx:series>
               </mx:PlotChart>
               <mx:Legend dataProvider="{myChart}"/>
            </mx:Panel>
          </mx:Application>
          

          1 person found this helpful
          • 2. Re: external XML data for plot chart
            Sen Imagines Level 1

            Greg,

             

            Thanks for your quick response.

             

            Since I am creating a plot chart that fetches the data from an external location (which will change or which is created dynamically by a server script code), I wish to have the XML as a separate file in an external location.

             

            - Sen