<?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"
xmlns:amcharts="http://www.amcharts.com/com_internal"
backgroundColor="#FFFFFF"
width="100%" height="100%" creationComplete="application1_creationCompleteHandler(event)"
xmlns:Classes="Classes.*">
<fx:Declarations>
<s:HTTPService id="piehs" result="piehs_resultHandler(event)" url="{hsurl}"/>
</fx:Declarations>
<fx:Script>
<![CDATA[
import flash.filters.DropShadowFilter;
import mx.collections.ArrayCollection;
import mx.controls.Alert;
import mx.core.FlexGlobals;
import mx.events.FlexEvent;
import mx.rpc.events.ResultEvent;
[Bindable]
private var shadow:DropShadowFilter = new DropShadowFilter(2,45,0,0.5);
//html传参数据
[Bindable]
public var regionTitle:String;
[Bindable]
public var TitleBollean:Boolean=true;
public var regionAlias:String;
public var valueAlias:String;
public var regionBoolean:Boolean;//是否映射
public var regions:Array;
[Bindable]
public var balloonBollean:Boolean=true;
[Bindable]
public var hsurl:String;
protected function application1_creationCompleteHandler(event:FlexEvent):void
{
var params:Object = FlexGlobals.topLevelApplication.parameters;//取出参数对象
//hsurl
if(params.hsurl!=null)
{
hsurl =params.hsurl;
}else{
Alert.show("无hsurl参数");
}
//balloonBollean
var _balloonBollean:String;
if(params.balloonBollean!=null)
{
_balloonBollean =params.balloonBollean;
}else{
Alert.show("无balloonBollean参数");
}
if(_balloonBollean=="yes"){
balloonBollean=true;
}else if(_balloonBollean=="no"){
balloonBollean=false;
}
//TitleBollean
var _TitleBollean:String;
if(params.TitleBollean!=null)
{
_TitleBollean =params.TitleBollean;
}else{
Alert.show("无TitleBollean参数");
}
if(_TitleBollean=="yes"){
TitleBollean=true;
}else if(_TitleBollean=="no"){
TitleBollean=false;
}
//regionTitle
if(params.regionTitle!=null)
{
regionTitle =params.regionTitle;
}else{
Alert.show("无regionTitle参数");
}
//regionAlias
if(params.regionAlias!=null)
{
regionAlias =params.regionAlias;
}else{
Alert.show("无regionAlias参数");
}
//valueAlias
if(params.valueAlias!=null)
{
valueAlias =params.valueAlias;
}else{
Alert.show("无valueAlias参数");
}
//regions
var _regions:String;
if(params.regions!=null)
{
_regions =params.regions;
}else{
Alert.show("无regions参数");
}
regions=_regions.split(",");
//regionBoolean
var _regionBoolean:String;
if(params.regionBoolean!=null)
{
_regionBoolean =params.regionBoolean;
}else{
Alert.show("无regionBoolean参数");
}
if(_regionBoolean=="yes"){
regionBoolean=true;
}else if(_regionBoolean=="no"){
regionBoolean=false;
}
piehs.send();
}
private var chartData:ArrayCollection;
private var tempAC:ArrayCollection;
[Bindable]
private var labeltext:String;
protected function piehs_resultHandler(event:ResultEvent):void
{
if(TitleBollean==true){
titlelabel.visible=true;
titlelabel.includeInLayout=true;
}else{
titlelabel.visible=false;
titlelabel.includeInLayout=false;
}
chartData=event.result.data.item as ArrayCollection;
var ac:ArrayCollection=new ArrayCollection();
//映射判断
//显示映射值及其他
if(regionBoolean==true&®ions!=null){
ac=new ArrayCollection();
tempAC= new ArrayCollection();
var tempACNEW:ArrayCollection=new ArrayCollection();
var temptwoAC:ArrayCollection=new ArrayCollection();
var temptwoACNEW:ArrayCollection=new ArrayCollection();
//解出reigons
for (var i:int = 0;i < chartData.length; i++)
{
var obj:Object = chartData[i] as Object;
var flag = false;
for(var j:int=0;j<regions.length;j++){
if(regions[j]==obj[regionAlias]){
tempAC.addItem(obj);//追加
flag = true;
}
}
if(flag){
continue;
}else{
}
}
//解出其他
var daobj:Object;
for (var k:int =chartData.length-1;k>=0; k--)
{
var obj:Object = chartData[k] as Object;
for(var l:int=0;l<regions.length;l++){
if(regions[l]==obj[regionAlias]){
daobj=new Object();
chartData.removeItemAt(k);
daobj=chartData;
}
}
}
temptwoAC.addItem(daobj);//追加
//其他整合
// for each(var elements:Object in temptwoAC[0]){
// var o:Object = new Object();
// o["value"] = elements[valueAlias];
// o["name"] ="其它数据";
// temptwoACNEW.addItem(o);
// }
//regions遍历
for each(var elements:Object in tempAC){
var o:Object = new Object();
o["value"] = elements[valueAlias];
o["name"] =elements[regionAlias];
tempACNEW.addItem(o);
}
ac.addAll(tempACNEW+temptwoACNEW);
pie.dataProvider=ac;
//只显示映射值
}else if(regionBoolean==false&®ions!=null){
ac=new ArrayCollection();
tempAC= new ArrayCollection();
for (var i:int = 0;i < chartData.length; i++)
{
var obj:Object = chartData[i] as Object;
for(var j:int=0;j<regions.length;j++){
if(regions[j]==obj[regionAlias]){
tempAC.addItem(obj);//追加
}
}
}
for each(var elements:Object in tempAC){
var o:Object = new Object();
o["value"] = elements[valueAlias];
o["name"] =elements[regionAlias];
ac.addItem(o);
}
pie.dataProvider=ac;
}
if(balloonBollean==true){
pieLegend.visible=true;
pieLegend.includeInLayout=true;
labeltext="[[percents]]%"
}else{
pieLegend.visible=false;
pieLegend.includeInLayout=false;
labeltext="[[title]]:<br>[[percents]]%"
}
}
]]>
</fx:Script>
<s:VGroup width="100%" height="100%" horizontalAlign="center" top="15">
<s:Label text="{regionTitle}" id="titlelabel" visible="{TitleBollean}" includeInLayout="{TitleBollean}"
fontFamily="宋体" fontSize="15" fontWeight="bold" color="#000000"/>
<s:HGroup width="100%" height="100%" horizontalAlign="center" verticalAlign="middle">
<Classes:AmPieChart
id="pie"
width="100%"
height="100%"
valueField="value"
marginBottom="40"
marginLeft="40"
marginRight="40"
marginTop="40"
pieAlpha="0.8"
titleField="name"
depth3D="30"
angle="20"
fontSize="12"
labelRadius="15"
fontFamily="宋体"
innerRadius="10"
groupPercent="0"
gradient="radial"
filters="{[shadow]}"
startDuration="1"
startRadius="100"
labelWidth="33"
balloonText = "[[title]]: [[percents]]% ([[value]])"
labelText="{labeltext}">
<Classes:balloon>
<amcharts:AmBalloon cornerRadius="3" borderThickness="2" borderColor="#FFFFFF" borderAlpha="1"/>
</Classes:balloon>
</Classes:AmPieChart>
<amcharts:AmLegend
visible="{balloonBollean}" includeInLayout="{balloonBollean}"
id="pieLegend" valueText=""
marginBottom="10"
marginLeft="10"
marginTop="10"
borderColor="#666666"
borderAlpha="1" align="left"
markerType="bubble"
width="165" height="100%"
textClickEnabled="false"
dataProvider="{pie}"
switchable="false"/>
<mx:Spacer width="15"/>
</s:HGroup>
</s:VGroup>
</s:Application>