1 Reply Latest reply on Apr 7, 2011 3:25 AM by Tanu Jain

    Filtering Dynamic XML data in a Chart

    tlobe432

      Hey, i was wondering if i could get some help. I am dynamically loading XML data and loading it into a chart. I am wondering how i could use a slider to change the data in the graph depending on the patent # and or the production # (I should be able to figure out the second one after i find out how to get the first one). Any Help is much appreciated. Thanks.

       

      This is what my xml looks like:

       

      <charts>

       

      <prospects>
      <month> Jan </month>
      <patent> 10800 </patent>
      <productions> 210020 </productions>
      </prospects>

       

      <prospects>
      <month> Feb </month>
      <patent> 10800 </patent>
      <productions> 210020 </productions>
      </prospects>

       

      <prospects>
      <month> Mar </month>
      <patent> 10800 </patent>
      <productions> 210020 </productions>
      </prospects>
      ...

      </charts>

       

      mxml looks like:

       

      <mx:HTTPService url="assets/test-data.xml" id="testData" result="xmlHandler(event)" resultFormat="e4x"/>

             </fx:Declarations>

            

             <fx:Script>

                    <![CDATA[

                           import mx.collections.ArrayCollection;

                           import mx.collections.ArrayList;

                           import mx.controls.Alert;

                           import mx.events.ListEvent;

                           import mx.rpc.events.ResultEvent;

                          

                           import scripts.Item;

                           import scripts.ItemXmlLoad;

                          

                           [Bindable]private var barChartInfo:XMLList;

                           [Bindable]private var lineChartInfo:XMLList;

                           [Bindable]private var pieChartInfo:XMLList;

                          

                           private function xmlHandler(evt:ResultEvent):void

                           {

                                 barChartInfo = evt.result.itemCosts;

                                 lineChartInfo = evt.result.prospects;

                                 pieChartInfo = evt.result.expenses;

                           }

                                                                                                      

                    ]]>

             </fx:Script>

                   

             <!-- Line Chart -->

             <mx:Panel horizontalAlign="center" title="Omega Prospect Sales" x="412.7" y="42.2" includeIn="graphs">

                   

                    <mx:LineChart dataProvider="{lineChartInfo}" id="lineChart" showDataTips="true">

                           <mx:horizontalAxis>

                                 <mx:CategoryAxis dataProvider="{lineChartInfo}" categoryField="month"/>

                           </mx:horizontalAxis>

                           <mx:series>

                                 <mx:LineSeries showDataEffect="{changeEffect}" yField="patent" displayName="Patent Sales"/>

                                 <mx:LineSeries showDataEffect="{changeEffect}" yField="production" displayName="Product Sales"/>

                           </mx:series>

                    </mx:LineChart>

                    <mx:Legend dataProvider="{lineChart}" includeIn="graphs"/>

             </mx:Panel>

            

      </s:Application>