Solved

Dynamically load XML via HTTPService tag for a chart

Posted on 2011-02-16
2
717 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
Comment Utility
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
Comment Utility
Excellent, splendid, fabulous, super human even...
0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

The Problem How to write an Xquery that works like a SQL outer join, providing placeholders for absent data on the outer side?  I give a bit more background at the end. The situation expressed as relational data Let’s work through this.  I’ve …
Introduction In my previous article (http://www.experts-exchange.com/Microsoft/Development/MS-SQL-Server/SSIS/A_9150-Loading-XML-Using-SSIS.html) I showed you how the XML Source component can be used to load XML files into a SQL Server database, us…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

771 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

10 Experts available now in Live!

Get 1:1 Help Now