Solved

Reading XML Attributes in Flex to generate Graphs

Posted on 2009-04-06
15
1,272 Views
Last Modified: 2013-11-18
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

0
Comment
Question by:rifaquat
  • 8
  • 7
15 Comments
 
LVL 37

Expert Comment

by:zzynx
ID: 24077171
Maybe you should show us what you already have
0
 

Author Comment

by:rifaquat
ID: 24077227
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

0
 
LVL 37

Expert Comment

by:zzynx
ID: 24077268
>> creationComplete="testData.send()"

What is testData?
0
 

Author Comment

by:rifaquat
ID: 24077284
sorry it was HTTPService i have removed it..so its no longer used.
0
 

Author Comment

by:rifaquat
ID: 24077295
I was using this before:
<mx:HTTPService url="myxml.xml" id="testData" result="xmlHandler(event)" resultFormat="e4x"/>

Open in new window

0
 
LVL 37

Expert Comment

by:zzynx
ID: 24077609
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

0
 

Author Comment

by:rifaquat
ID: 24077800
Thanks mate..Can i ask u one more question i will add more points then?
0
6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

 
LVL 37

Expert Comment

by:zzynx
ID: 24077862
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.
0
 

Author Comment

by:rifaquat
ID: 24077927
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.
0
 
LVL 37

Accepted Solution

by:
zzynx earned 250 total points
ID: 24078186
I don't think that is related with this question.
It's about the use of a combo box.
Better close this Q and ask that in another Q.

As a first help I would already give you this link:
http://blog.3alves.com/blog/post/2007/08/23/Flex-ComboBox-using-XML.aspx
0
 
LVL 37

Expert Comment

by:zzynx
ID: 24078352
Thanx 4 axxepting
0
 

Author Comment

by:rifaquat
ID: 24078471
Now can you please answere the question i asked about combo box?
0
 
LVL 37

Expert Comment

by:zzynx
ID: 24081271
>> Now can you please answere the question i asked about combo box?
Can you provide me the link of that new question?
0
 

Author Comment

by:rifaquat
ID: 24085524
0
 
LVL 37

Expert Comment

by:zzynx
ID: 24086073
I see that the first link in the first comment that Q already got, is the one I already provided you.
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Introduction Since I wrote the original article about Handling Date and Time in PHP and MySQL (http://www.experts-exchange.com/articles/201/Handling-Date-and-Time-in-PHP-and-MySQL.html) several years ago, it seemed like now was a good time to updat…
JavaScript has plenty of pieces of code people often just copy/paste from somewhere but never quite fully understand. Self-Executing functions are just one good example that I'll try to demystify here.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

746 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now