Solved

How to populate XML Data in Flex Pie Charts

Posted on 2011-02-23
4
943 Views
Last Modified: 2012-05-11
Hi,
    I need to populate a pie chart component with XML data in Flex....I just want to show high cost and low cost in the first stage and then drill down to the the leaf nodes...I have attached the code below....


Thanks In Advance....


 
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:

	

private function handlegetBranchDetailsResult(event:ResultEvent):void
		{
			acDetails = new XML();
			acDetails = null;
			acDetails = event.result as XML;
			argumentList = XMLList(acDetails.root);
			Alert.show("Data Received");
		}
			
		private function handlegetBranchDetailsFault(event:FaultEvent):void
		{
			Alert.show("in handle get Branch Details Fault : "+event.fault.faultString+" ");
		}
		
	]]>
</mx:Script>


	<mx:TitleWindow height="730" width="100%" layout="absolute">
	<mx:HDividedBox x="5" y="10" width="100%">
		<mx:VBox width="50%" horizontalAlign="center" verticalAlign="middle">
			<mx:Label text="Total Deposits:"/>
			<mx:PieChart id="pcDepostis0" showDataTips="true" dataProvider="{argumentList}" width="100%" x="10" y="37">
				<mx:series>
					<mx:PieSeries displayName="Name" field="Totamt" labelPosition="callout"/>
				</mx:series>
			</mx:PieChart>
			<mx:HBox>
				<mx:Label text="Low Cost:"/>
				<mx:Label text="--"/>
				<mx:Label text="%"/>
			</mx:HBox>
			<mx:HBox>
				<mx:Label text="High Cost:"/>
				<mx:Label text="--"/>
				<mx:Label text="%"/>
			</mx:HBox>
			<mx:Legend dataProvider="{pcDepostis0}" color="#ffffff"/>

			<mx:Spacer/>
		</mx:VBox>
		<mx:VBox width="50%" horizontalAlign="center" verticalAlign="middle">
			<mx:Label text="Total Advances:"/>
			<mx:PieChart id="advDepostis" width="100%">
				<mx:series>
					<mx:PieSeries displayName="Series 1" field=""/>
				</mx:series>
			</mx:PieChart>			
		</mx:VBox>
		</mx:HDividedBox>
		<mx:ControlBar height="54">
			<mx:Spacer width="100%"/>
			<mx:Button label="EXIT" width="80" click="btnCancelClicked()"/>
		</mx:ControlBar>
	</mx:TitleWindow>
</mx:Module>

Open in new window


     

The XML File....


 
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:

	

private function handlegetBranchDetailsResult(event:ResultEvent):void
		{
			acDetails = new XML();
			acDetails = null;
			acDetails = event.result as XML;
			argumentList = XMLList(acDetails.root);
			Alert.show("Data Received");
		}
			
		private function handlegetBranchDetailsFault(event:FaultEvent):void
		{
			Alert.show("in handle get Branch Details Fault : "+event.fault.faultString+" ");
		}
		
	]]>
</mx:Script>


	<mx:TitleWindow height="730" width="100%" layout="absolute">
	<mx:HDividedBox x="5" y="10" width="100%">
		<mx:VBox width="50%" horizontalAlign="center" verticalAlign="middle">
			<mx:Label text="Total Deposits:"/>
			<mx:PieChart id="pcDepostis0" showDataTips="true" dataProvider="{argumentList}" width="100%" x="10" y="37">
				<mx:series>
					<mx:PieSeries displayName="Name" field="Totamt" labelPosition="callout"/>
				</mx:series>
			</mx:PieChart>
			<mx:HBox>
				<mx:Label text="Low Cost:"/>
				<mx:Label text="--"/>
				<mx:Label text="%"/>
			</mx:HBox>
			<mx:HBox>
				<mx:Label text="High Cost:"/>
				<mx:Label text="--"/>
				<mx:Label text="%"/>
			</mx:HBox>
			<mx:Legend dataProvider="{pcDepostis0}" color="#ffffff"/>

			<mx:Spacer/>
		</mx:VBox>
		<mx:VBox width="50%" horizontalAlign="center" verticalAlign="middle">
			<mx:Label text="Total Advances:"/>
			<mx:PieChart id="advDepostis" width="100%">
				<mx:series>
					<mx:PieSeries displayName="Series 1" field=""/>
				</mx:series>
			</mx:PieChart>			
		</mx:VBox>
		</mx:HDividedBox>
		<mx:ControlBar height="54">
			<mx:Spacer width="100%"/>
			<mx:Button label="EXIT" width="80" click="btnCancelClicked()"/>
		</mx:ControlBar>
	</mx:TitleWindow>
</mx:Module>

Open in new window




Do I need to use the XML as XML itself or as XML List....
<?xml version="1.0" encoding="UTF-8"?>
<root>
<LowCost Name="Low Cost" Totamt="378255439.64000005">
<Savings Name="Savings" Totamt="315606393.47"/>
<RoSavings Name="NRO Savings" Totamt="869313.80"/>
<Current Name="Current" Totamt="35627467.37"/>
<ReSavings Name="NRE Savings" Totamt="23602298.18"/>
<Crod Name="CROD" Totamt="2549966.82"/>
</LowCost>
<HighCost Name="High Cost" Totamt="560904429.25">
<Fdr Name="FDR" Totamt="9160151.70"/>
<Qirp Name="QIRP" Totamt="28609765.00"/>
<Mip Name="MIP" Totamt="1461211.20"/>
<Std Name="STD" Totamt="0.00"/>
<Rd Name="RD" Totamt="5642603.40"/>
<Rap30 Name="RAP 30" Totamt="3014440.00"/>
<Rap90 Name="RAP 90" Totamt="173740227.00"/>
<Rap Name="RAP" Totamt="0.00"/>
<Fdr365 Name="FDR 365" Totamt="336095018.95"/>
<Nrefdr Name="NRE FDR" Totamt="50024.00"/>
<Nreqrp Name="NRE QRP" Totamt="3130988.00"/>
<Nremip Name="NRE MIP" Totamt="0.00"/>
<Nrerd Name="NRE RD" Totamt="0.00"/>
<Nrerap Name="NRE RAP" Totamt="0.00"/>
<Nrofdr Name="NRO FDR" Totamt="0.00"/>
<Nroqrp Name="NRO QRP" Totamt="0.00"/>
<Nromip Name="NRO MIP" Totamt="0.00"/>
<Nrord Name="NRO RD" Totamt="0.00"/>
<Nrorap Name="NRO RAP" Totamt="0.00"/>
</HighCost>
</root>

Open in new window

0
Comment
Question by:CCBRONET
  • 2
4 Comments
 
LVL 29

Accepted Solution

by:
dgofman earned 500 total points
ID: 35134682
Use XMLLIst Collection you can also include labelFunction or format/group values

<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
                     xmlns:s="library://ns.adobe.com/flex/spark"
                     xmlns:mx="library://ns.adobe.com/flex/mx">
      <s:layout>
            <s:HorizontalLayout/>
      </s:layout>
      <fx:Declarations>
      <mx:XMLListCollection id="dp">
            <mx:source>
                  <fx:XMLList>
                        <LowCost Name="Low Cost" Totamt="378255439.64000005">
                              <Savings Name="Savings" Totamt="315606393.47"/>
                              <RoSavings Name="NRO Savings" Totamt="869313.80"/>
                              <Current Name="Current" Totamt="35627467.37"/>
                              <ReSavings Name="NRE Savings" Totamt="23602298.18"/>
                              <Crod Name="CROD" Totamt="2549966.82"/>
                        </LowCost>
                        <HighCost Name="High Cost" Totamt="560904429.25">
                              <Fdr Name="FDR" Totamt="9160151.70"/>
                              <Qirp Name="QIRP" Totamt="28609765.00"/>
                              <Mip Name="MIP" Totamt="1461211.20"/>
                              <Std Name="STD" Totamt="0.00"/>
                              <Rd Name="RD" Totamt="5642603.40"/>
                              <Rap30 Name="RAP 30" Totamt="3014440.00"/>
                              <Rap90 Name="RAP 90" Totamt="173740227.00"/>
                              <Rap Name="RAP" Totamt="0.00"/>
                              <Fdr365 Name="FDR 365" Totamt="336095018.95"/>
                              <Nrefdr Name="NRE FDR" Totamt="50024.00"/>
                              <Nreqrp Name="NRE QRP" Totamt="3130988.00"/>
                              <Nremip Name="NRE MIP" Totamt="0.00"/>
                              <Nrerd Name="NRE RD" Totamt="0.00"/>
                              <Nrerap Name="NRE RAP" Totamt="0.00"/>
                              <Nrofdr Name="NRO FDR" Totamt="0.00"/>
                              <Nroqrp Name="NRO QRP" Totamt="0.00"/>
                              <Nromip Name="NRO MIP" Totamt="0.00"/>
                              <Nrord Name="NRO RD" Totamt="0.00"/>
                              <Nrorap Name="NRO RAP" Totamt="0.00"/>
                        </HighCost>
                  </fx:XMLList>
            </mx:source>
      </mx:XMLListCollection>
      </fx:Declarations>
      <mx:PieChart id="pieChart"
                         dataProvider="{dp}"
                         showDataTips="true"  >
            <mx:series>
                  <mx:PieSeries id="pieSeries"
                                      field="@Totamt"
                                      nameField="@Name"
                                      labelPosition="inside" >
                        
                        
                  </mx:PieSeries>
            </mx:series>
      </mx:PieChart>
</s:Application>
0
 
LVL 29

Expert Comment

by:dgofman
ID: 35158356
The question close after 4 days when I gave my answer. And this answer is correct.
Please can you add points to my account?
Thanks,
David
0

Featured Post

IT, Stop Being Called Into Every Meeting

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

Suggested Solutions

Styling your websites can become very complex. Here I'll show how SASS can help you better organize, maintain and reuse your CSS code.
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.
HTML5 has deprecated a few of the older ways of showing media as well as offering up a new way to create games and animations. Audio, video, and canvas are just a few of the adjustments made between XHTML and HTML5. As we learned in our last micr…
The goal of the tutorial is to teach the user how to select which audio input to use. Once you have an audio input plugged into the laptop or computer, you will go into the audio input settings and choose which audio input you want to use.

759 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

20 Experts available now in Live!

Get 1:1 Help Now