0 Replies Latest reply on Nov 9, 2010 3:18 AM by Sen Imagines

    XML data for Chart series

    Sen Imagines

      Hi,

       

      I am using Flex 3 Plot chart.

       

      I feed the chart with data from an external XML file thru a HTTPService.

      In the result handler of the HTTPService, I parse the XML data & create sub XML's based on certain nodes of the original XML data.

       

      I use 2 plot chart series. I want to provide the generated sub XML data as the DataProvider to the plot series.

       

      I am not getting the plotted chart.

       

      Here's my code:

      -------------------------

      <?xml version="1.0"?>

      <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" xmlns:local="*" layout="absolute" initialize="init()" creationComplete="srv.send()">

      <mx:HTTPService id="srv" url="myProjectsData.xml" resultFormat="e4x" result="myResultHandler()" />
          <mx:Script>
              <![CDATA[
              import mx.collections.ArrayCollection;
              import mx.charts.renderers.*;
              import flash.events.Event;       
              import mx.events.DropdownEvent;
              import mx.rpc.events.FaultEvent;
         
                import mx.controls.Alert;
             
              import mx.charts.events.ChartItemEvent;
        
           [Bindable]
           public var highCostXML:XML;
          
           [Bindable]
           public var lowCostXML:XML;
      public function myResultHandler():void
      {
           var myDataXML:XML;
           lowCostXML = new XML("<projects></projects>");
           highCostXML = new XML("<projects></projects>");
           myDataXML = new XML(srv.lastResult);
           for each(var tempXML:XML in myDataXML.project)
           {
                if(tempXML.hasOwnProperty("CostHigh"))
                {
                     highCostXML = highCostXML.appendChild(tempXML);
                }
                else
                {
                     lowCostXML = lowCostXML.appendChild(tempXML);
                }
           }
           Alert.show(lowCostXML.toXMLString());
           LowSeries.dataProvider = lowCostXML.project;
           Alert.show("LowCost");
           Alert.show(highCostXML.toXMLString());
           Alert.show("HighCost");
           HighSeries.dataProvider = highCostXML.project;
      }
              <mx:PlotChart id="myInteractiveChart"
                  height="100%"
                  width="100%"
                  itemSelectionColor="black" 
                  showDataTips="true"
                  dataTipFunction="myDataTipFunction" selectionMode="single"
              >               
             
              <mx:verticalAxis>
                 <mx:LinearAxis title="Cost" />
                 </mx:verticalAxis>
             
              <mx:horizontalAxis>
                 <mx:LinearAxis title="% Complete"/>
              </mx:horizontalAxis>
             
                  <mx:series>
                      <mx:PlotSeries id="LowSeries" xField="PerComp" yField="CostLow" displayName="Low Cost" radius="8"                   
                          fill="{lowfill}"
                          stroke="{lowstroke}"
                          itemRenderer="mx.charts.renderers.CircleItemRenderer"
                      />
                      <mx:PlotSeries
                      id="HighSeries" xField="PerComp" yField="CostHigh" displayName="High Cost" radius="8"
                          fill="{highfill}"
                          stroke="{highstroke}"
                          itemRenderer="mx.charts.renderers.CircleItemRenderer"                   
                      />
                  </mx:series>
              </mx:PlotChart>
      The Sample XML data:
      ------------------------------------
      <?xml version="1.0" encoding="utf-8"?>
      <projects>
           <project PerComp="10">
                <ProjID>1038</ProjID>
                <ProjName>MyProj1</ProjName>
           <CostHigh>2</CostHigh>
      </project>
      <project PerComp="12">
           <ProjID>1055</ProjID>
                <ProjName>MyProj2</ProjName>
                <CostLow>0</CostLow>
           </project>
      </projects>