Solved

How to populate XML Data in Flex Pie Charts

Posted on 2011-02-23
4
973 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

Question has a verified solution.

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

When it comes to write a Context Sensitive Help (an online help that is obtained from a specific point in state of software to provide help with that state) ,  first we need to make the file that contains all topics, which are given exclusive IDs. …
Australian government abolished Visa 457 earlier this April and this article describes how this decision might affect Australian IT scene and IT experts.
The viewer will get a basic understanding of what section 508 compliance can entail, learn about skip navigation links, alt text, transcripts, and font size controls.
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

617 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