Link to home
Start Free TrialLog in
Avatar of rifaquat
rifaquatFlag for United Kingdom of Great Britain and Northern Ireland

asked on

Reading XML Attributes in Flex to generate Graphs

Hi

I am developing an app on Flex to generate bar chart. I have the following XML file. At the moment i can read the XML attribute but having problem in binding the data with the graph. I want to create a multiple bar chart.

On X axis we have WeekNo-1 and so on...

On Yaxis we want to have the value from 'complete' attribute in the <week> tag.

Any help would be much appreciated.
<?xml version="1.0" encoding="UTF-8"?>
<Data>
<Overall GoogleUniqVisitorOverall="0"  GoogleUniqVisitorOverallPerc="100"  CompleteOverall="14958" CompleteOverallPercentage="0" TelOptOutFalseOverall="6078" TelOptOutFalseOverallPerc="0" />
<Cycle CycleID="2" RMCycleID="08/09 - Cycle 2">
	<Week WeekStart="29/09/2008" WeekNo="1" CompletePredicted="0" Complete="679" Uncomplete="691" TelSupplied="0" TelOptOutFalse="646" GoogleUniqVisitorPredicted="0" GoogleUniqVisitor="0" />
	<Week WeekStart="06/10/2008" WeekNo="2" CompletePredicted="0" Complete="1283" Uncomplete="1112" TelSupplied="0" TelOptOutFalse="1229" GoogleUniqVisitorPredicted="0" GoogleUniqVisitor="0" />
	<Week WeekStart="13/10/2008" WeekNo="3" CompletePredicted="0" Complete="913" Uncomplete="1046" TelSupplied="0" TelOptOutFalse="863" GoogleUniqVisitorPredicted="0" GoogleUniqVisitor="0" />
	<Week WeekStart="20/10/2008" WeekNo="4" CompletePredicted="0" Complete="946" Uncomplete="880" TelSupplied="0" TelOptOutFalse="742" GoogleUniqVisitorPredicted="0" GoogleUniqVisitor="0" />
	<Week WeekStart="27/10/2008" WeekNo="5" CompletePredicted="0" Complete="757" Uncomplete="796" TelSupplied="0" TelOptOutFalse="37" GoogleUniqVisitorPredicted="0" GoogleUniqVisitor="0" />
	<Week WeekStart="03/11/2008" WeekNo="6" CompletePredicted="0" Complete="823" Uncomplete="912" TelSupplied="0" TelOptOutFalse="40" GoogleUniqVisitorPredicted="0" GoogleUniqVisitor="0" />
 
	<Week WeekStart="10/11/2008" WeekNo="7" CompletePredicted="0" Complete="890" Uncomplete="948" TelSupplied="0" TelOptOutFalse="52" GoogleUniqVisitorPredicted="0" GoogleUniqVisitor="0" />
	<Week WeekStart="17/11/2008" WeekNo="8" CompletePredicted="0" Complete="704" Uncomplete="771" TelSupplied="0" TelOptOutFalse="39" GoogleUniqVisitorPredicted="0" GoogleUniqVisitor="0" />
	<Week WeekStart="24/11/2008" WeekNo="9" CompletePredicted="0" Complete="552" Uncomplete="706" TelSupplied="0" TelOptOutFalse="36" GoogleUniqVisitorPredicted="0" GoogleUniqVisitor="0" />
	<Week WeekStart="01/12/2008" WeekNo="10" CompletePredicted="0" Complete="1012" Uncomplete="597" TelSupplied="0" TelOptOutFalse="334" GoogleUniqVisitorPredicted="0" GoogleUniqVisitor="0" />
	<Week WeekStart="08/12/2008" WeekNo="11" CompletePredicted="0" Complete="523" Uncomplete="661" TelSupplied="0" TelOptOutFalse="166" GoogleUniqVisitorPredicted="0" GoogleUniqVisitor="0" />
	<Week WeekStart="15/12/2008" WeekNo="12" CompletePredicted="0" Complete="354" Uncomplete="452" TelSupplied="0" TelOptOutFalse="97" GoogleUniqVisitorPredicted="0" GoogleUniqVisitor="0" />
	<Week WeekStart="22/12/2008" WeekNo="13" CompletePredicted="0" Complete="146" Uncomplete="258" TelSupplied="0" TelOptOutFalse="49" GoogleUniqVisitorPredicted="0" GoogleUniqVisitor="0" />
	<Week WeekStart="29/12/2008" WeekNo="14" CompletePredicted="0" Complete="331" Uncomplete="379" TelSupplied="0" TelOptOutFalse="100" GoogleUniqVisitorPredicted="0" GoogleUniqVisitor="0" />
	<CyclePeriod Start="29/09/2008" End="04/01/2009" />
</Cycle>
 
</Data>

Open in new window

Avatar of zzynx
zzynx
Flag of Belgium image

Maybe you should show us what you already have
Avatar of rifaquat

ASKER

here you are
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" creationComplete="testData.send()" width="1044"  horizontalAlign="center" verticalAlign="middle" height="630">
  
	<mx:SeriesInterpolate id="changeEffect" duration="2000"/>
	<mx:XML id="myXML" source="myXML"/>
   		
 	
 	<mx:Panel horizontalAlign="center" title="Revenue" x="120.5" y="103" height="339" width="803">
	  <mx:ColumnChart dataProvider="{myXML.Cycle.Week}" id="testChart" showDataTips="true" height="211" width="532">
		  <mx:horizontalAxis>
		  	<mx:CategoryAxis dataProvider="{myXML.Cycle.Week}" categoryField="WeekNo"/>
     	  </mx:horizontalAxis>
	 	  <mx:series>
		  	<mx:ColumnSeries showDataEffect="changeEffect" xField="{myXML.Cycle.Week.@WeekNo}" yField="myXML.Cycle.Week.@complete" displayName="Revenue"/>
		  </mx:series>
	  </mx:ColumnChart>
 
 
	</mx:Panel>
		<mx:TextArea id="something" text="Test" x="386" y="494" width="306"/> 
 
	<mx:Script>
		<![CDATA[
		import mx.controls.Text;
		import mx.rpc.events.ResultEvent;
		//import mx.collections.ArrayCollection;
		 
		[Bindable]
		private var testInfo:XMLList;
		
	 
		 
		private function xmlHandler(evt:ResultEvent):void{
 
		  
			 
			testInfo = evt.result.Cycle;
		
	 
			 
			trace("printing Complete\n"+ myXML.Cycle.Week.@WeekNo);
			
		}
	    
	   
	    
	    
		]]>
	</mx:Script>
 
</mx:Application>

Open in new window

>> creationComplete="testData.send()"

What is testData?
sorry it was HTTPService i have removed it..so its no longer used.
I was using this before:
<mx:HTTPService url="myxml.xml" id="testData" result="xmlHandler(event)" resultFormat="e4x"/>

Open in new window

Consider this code:
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" 
		width="1044"  horizontalAlign="center" verticalAlign="middle" height="630">
  
        <mx:SeriesInterpolate id="changeEffect" duration="2000"/>
 
		<mx:XMLListCollection id="data">
			<mx:source>
    			<mx:XMLList>
						<Week WeekStart="29/09/2008" WeekNo="1" CompletePredicted="0" Complete="679" Uncomplete="691" TelSupplied="0" TelOptOutFalse="646" GoogleUniqVisitorPredicted="0" GoogleUniqVisitor="0" />
				        <Week WeekStart="06/10/2008" WeekNo="2" CompletePredicted="0" Complete="1283" Uncomplete="1112" TelSupplied="0" TelOptOutFalse="1229" GoogleUniqVisitorPredicted="0" GoogleUniqVisitor="0" />
				        <Week WeekStart="13/10/2008" WeekNo="3" CompletePredicted="0" Complete="913" Uncomplete="1046" TelSupplied="0" TelOptOutFalse="863" GoogleUniqVisitorPredicted="0" GoogleUniqVisitor="0" />
				        <Week WeekStart="20/10/2008" WeekNo="4" CompletePredicted="0" Complete="946" Uncomplete="880" TelSupplied="0" TelOptOutFalse="742" GoogleUniqVisitorPredicted="0" GoogleUniqVisitor="0" />
				        <Week WeekStart="27/10/2008" WeekNo="5" CompletePredicted="0" Complete="757" Uncomplete="796" TelSupplied="0" TelOptOutFalse="37" GoogleUniqVisitorPredicted="0" GoogleUniqVisitor="0" />
				        <Week WeekStart="03/11/2008" WeekNo="6" CompletePredicted="0" Complete="823" Uncomplete="912" TelSupplied="0" TelOptOutFalse="40" GoogleUniqVisitorPredicted="0" GoogleUniqVisitor="0" />
 
				        <Week WeekStart="10/11/2008" WeekNo="7" CompletePredicted="0" Complete="890" Uncomplete="948" TelSupplied="0" TelOptOutFalse="52" GoogleUniqVisitorPredicted="0" GoogleUniqVisitor="0" />
				        <Week WeekStart="17/11/2008" WeekNo="8" CompletePredicted="0" Complete="704" Uncomplete="771" TelSupplied="0" TelOptOutFalse="39" GoogleUniqVisitorPredicted="0" GoogleUniqVisitor="0" />
				        <Week WeekStart="24/11/2008" WeekNo="9" CompletePredicted="0" Complete="552" Uncomplete="706" TelSupplied="0" TelOptOutFalse="36" GoogleUniqVisitorPredicted="0" GoogleUniqVisitor="0" />
				        <Week WeekStart="01/12/2008" WeekNo="10" CompletePredicted="0" Complete="1012" Uncomplete="597" TelSupplied="0" TelOptOutFalse="334" GoogleUniqVisitorPredicted="0" GoogleUniqVisitor="0" />
				        <Week WeekStart="08/12/2008" WeekNo="11" CompletePredicted="0" Complete="523" Uncomplete="661" TelSupplied="0" TelOptOutFalse="166" GoogleUniqVisitorPredicted="0" GoogleUniqVisitor="0" />
				        <Week WeekStart="15/12/2008" WeekNo="12" CompletePredicted="0" Complete="354" Uncomplete="452" TelSupplied="0" TelOptOutFalse="97" GoogleUniqVisitorPredicted="0" GoogleUniqVisitor="0" />
				        <Week WeekStart="22/12/2008" WeekNo="13" CompletePredicted="0" Complete="146" Uncomplete="258" TelSupplied="0" TelOptOutFalse="49" GoogleUniqVisitorPredicted="0" GoogleUniqVisitor="0" />
				        <Week WeekStart="29/12/2008" WeekNo="14" CompletePredicted="0" Complete="331" Uncomplete="379" TelSupplied="0" TelOptOutFalse="100" GoogleUniqVisitorPredicted="0" GoogleUniqVisitor="0" />
    			</mx:XMLList>
			</mx:source>
		</mx:XMLListCollection>
        
        
        <mx:Panel horizontalAlign="center" title="Revenue" x="120.5" y="103" height="339" width="803">
          <mx:ColumnChart dataProvider="{data}" id="testChart" showDataTips="true" height="211" width="532">
                  <mx:horizontalAxis>
                        <mx:CategoryAxis categoryField="@WeekNo"/>
          </mx:horizontalAxis>
                  <mx:series>
                        <mx:ColumnSeries showDataEffect="changeEffect" 
                        	xField="@WeekNo" 
                        	yField="@Complete" 
                        	displayName="Revenue"/>
                  </mx:series>
          </mx:ColumnChart>
 
 
        </mx:Panel>
                <mx:TextArea id="something" text="Test" x="386" y="494" width="306"/> 
 
        <mx:Script>
                <![CDATA[
                ]]>
        </mx:Script>
 
</mx:Application>

Open in new window

Thanks mate..Can i ask u one more question i will add more points then?
You're welcome.

>> Can i ask u one more question
If it's somewhat related, yes.
If not, close this one and ask open one.
In my xml i have a 'CycleID' attribute and then in the 'Cycle period' tag i have start and End date. How would i populate it in a combo box something like:

1) Cycle 2 - 20/01/2009 to 25/01/2009 and so on... and then i want to get the cycle ID from the combo box when its clicked.

Thanks.
ASKER CERTIFIED SOLUTION
Avatar of zzynx
zzynx
Flag of Belgium image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanx 4 axxepting
Now can you please answere the question i asked about combo box?
>> Now can you please answere the question i asked about combo box?
Can you provide me the link of that new question?
I see that the first link in the first comment that Q already got, is the one I already provided you.