Solved

Dynamically load XML via HTTPService tag for a chart

Posted on 2011-02-16
2
720 Views
Last Modified: 2012-05-11

Just point the
<mx:HTTPService id="srv"

Open in new window

to the xml file?

or

Do I need to implement E4X?




Example from Flex4 Adobe site:

<s:Application 
	xmlns:fx="http://ns.adobe.com/mxml/2009" 
	xmlns:mx="library://ns.adobe.com/flex/mx" 
	xmlns:s="library://ns.adobe.com/flex/spark" 
	creationComplete="initApp();srv.send();"
	height="600">
	
	<fx:Declarations>
		<!-- View source of the following page to see the structure of the data that Flex uses in this example. -->
		<mx:HTTPService id="srv" url="http://aspexamples.adobe.com/chart_examples/networth-xml.aspx"/>
		<!-- To see data in an HTML table, go to http://aspexamples.adobe.com/chart_examples/networth.aspx -->  
	</fx:Declarations>
	
	<fx:Script><![CDATA[
		public var initSeriesArray:Array = new Array();
		public var level:Number = 1;
		public var newSeries:Array;
		
		private function initApp():void {
			// Get initial series Array -- to be reloaded when it returns 
			// from a drill down.
			initSeriesArray = chart.series;             
		}
		
		private function zoomIntoSeries(e:Event):void {
			newSeries = new Array();
			if (level == 1) {
				newSeries.push(e.currentTarget);   
				level = 2; 
			} else {
				newSeries = initSeriesArray;
				p1.title = "Net Worth";
				level = 1;
			}           
			chart.series = newSeries;            
		}
		
	]]></fx:Script>
	
	<s:layout>
		<s:VerticalLayout/>
	</s:layout>
	
	<s:Panel id="p1" title="Net Worth">
		<s:layout>
			<s:VerticalLayout/>
		</s:layout>
		<mx:ColumnChart id="chart" 
						dataProvider="{srv.lastResult.data.result}" 
						type="stacked" 
						showDataTips="true">
			<mx:series> 
				<mx:ColumnSeries id="s1" 
								 displayName="Cash" 
								 yField="cash" 
								 xField="date" 
								 click="zoomIntoSeries(event)"/>
				<mx:ColumnSeries id="s2" 
								 displayName="Stocks" 
								 yField="stocks"  
								 xField="date"  
								 click="zoomIntoSeries(event)"/>
				<mx:ColumnSeries id="s3" 
								 displayName="Retirement" 
								 yField="retirement" 
								 xField="date" 
								 click="zoomIntoSeries(event)"/>
				<mx:ColumnSeries id="s4" 
								 displayName="Home" 
								 yField="home" 
								 xField="date" 
								 click="zoomIntoSeries(event)"/>
				<mx:ColumnSeries id="s5" 
								 displayName="Other" 
								 yField="other" 
								 xField="date" 
								 click="zoomIntoSeries(event)"/>
			</mx:series>            
			<mx:horizontalAxis >
				<mx:DateTimeAxis title="Date" dataUnits="months"/>
			</mx:horizontalAxis>    
		</mx:ColumnChart> 
		<mx:Legend dataProvider="{chart}"/>
	</s:Panel>
</s:Application>

Open in new window

0
Comment
Question by:mebibyte
2 Comments
 
LVL 17

Accepted Solution

by:
deepanjandas earned 500 total points
ID: 34913365
Use Bindable XMLList as dataprovider, hence e4X will be required. Try this:
//XML List for loaded XML file. Must be bindable!
[Bindable]
private var chartInfo:XMLList;

private function xmlHandler(evt:ResultEvent):void{
    //Sets chartInfo's root as data. Everything else referenced in respect to this.
    chartInfo = evt.result;
}

Open in new window


In the Chart use this chartInfo variable:
 
<mx:ColumnChart id="chart" dataProvider="{chartInfo}" type="stacked" showDataTips="true">

Open in new window



Warm Regards
Deepanjan Das
0
 

Author Closing Comment

by:mebibyte
ID: 34913411
Excellent, splendid, fabulous, super human even...
0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The Client Need Led Us to RSS I recently had an investment company ask me how they might notify their constituents about their newsworthy publications.  Probably you would think "Facebook" or "Twitter" but this is an interesting client.  Their cons…
Browsing the questions asked to the Experts of this forum, you will be amazed to see how many times people are headaching about monster regular expressions (regex) to select that specific part of some HTML or XML file they want to extract. The examp…
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …

816 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

12 Experts available now in Live!

Get 1:1 Help Now