【Flex】Flex+二维饼图,PieChart3D,后台使用XML传说数据绑定饼
发布时间:2020-12-15 01:26:29 所属栏目:百科 来源:网络整理
导读:? Actionscript代码ArrayCollection返回该类型 ?xml version="1.0" encoding="utf-8"?mx:Module xmlns:fx="http://ns.adobe.com/mxml/2009" xmlns:s="library://ns.adobe.com/flex/spark" xmlns:mx="library://ns.adobe.com/flex/mx" layout="absolute" widt
? Actionscript代码ArrayCollection返回该类型 <?xml version="1.0" encoding="utf-8"?> <mx:Module xmlns:fx="http://ns.adobe.com/mxml/2009" xmlns:s="library://ns.adobe.com/flex/spark" xmlns:mx="library://ns.adobe.com/flex/mx" layout="absolute" width="100%" height="100%" creationComplete="init(event)" xmlns:ilog="http://www.ilog.com/2007/ilog/flex"> <mx:Legend legendItemClass="gds.util.BigFontLegendItem "/> <fx:Style> .ChineseFont { fontSize:14; } </fx:Style> <fx:Script> <![CDATA[ import mx.collections.ArrayCollection; import mx.collections.XMLListCollection; import mx.controls.Alert; import mx.events.FlexEvent; import mx.rpc.events.FaultEvent; import mx.rpc.events.ResultEvent; import spark.events.IndexChangeEvent; [Bindable] private var xmlData:XMLListCollection = new XMLListCollection(); //信息统计的集合 [Bindable] private var yearList:ArrayCollection = new ArrayCollection(); //年份 [Bindable] public var tjfsDP:ArrayCollection = new ArrayCollection([{ label: "按故障类型统计",data: 0 },{ label: "按任务类型统计",data: 1 }]); /** * 初始化方法 * */ private function init (event:FlexEvent):void { statisticsViewService.findApplyYear(); //年份下拉框初始化 } /** * 后台调用出错 * */ private function isError (event:FaultEvent):void { Alert.show(event.fault.faultString,"操作提示"); } /** * 按故障类型统计故障信息回调 **/ private function backStatisticsFaultInfoByFaultType (event:ResultEvent):void { var aXML:XML = event.result as XML; if (aXML != null) { xmlData.removeAll(); xmlData = new XMLListCollection(aXML.children()); } chartHGroup.visible = true; } /** * 按任务解决状态统计故障信息回调 * */ private function backStatisticsFaultInfoByTaskStatus (event:ResultEvent):void { var aXML:XML = event.result as XML; if (aXML != null) { xmlData.removeAll(); xmlData = new XMLListCollection(aXML.children()); } chartHGroup.visible = true; } /** * 根据年份查询回调函数 * */ private function backFindYear (event:ResultEvent):void { yearList = event.result as ArrayCollection; year.dataProvider = yearList; year.selectedIndex = 0; statisticsViewService.statisticsFaultInfoByFaultType(year.selectedItem); } /*** * 年份发生变化的时候 * */ private function year_changeHandler (event:IndexChangeEvent):void { chartHGroup.visible = false; } /** * * 点击查看 * */ private function bt_find (event:MouseEvent):void { var aYear:String = year.selectedItem as String; //得到年份 var tjfs:int = tjfsDPDDL.selectedIndex; //得到统计方式 //判断统计方式按什么查询 if (tjfs == 0) { statisticsViewService.statisticsFaultInfoByFaultType(aYear); } else if (tjfs == 1) { statisticsViewService.statisticsFaultInfoByTaskStatus(aYear); } } /** * 统计方式发生改变 * */ private function tjfsDP_changeHandler (event:IndexChangeEvent):void { chartHGroup.visible = false; } ]]> </fx:Script> <fx:Declarations> <!-- 将非可视元素(例如服务、值对象)放在此处 --> <s:RemoteObject id="statisticsViewService" destination="statisticsViewService" showBusyCursor="true"> <s:method name="statisticsFaultInfoByFaultType" result="backStatisticsFaultInfoByFaultType(event)" fault="isError(event)"/> <s:method name="findApplyYear" result="backFindYear(event)" fault="isError(event)"/> <s:method name="statisticsFaultInfoByTaskStatus" result="backStatisticsFaultInfoByTaskStatus(event)" fault="isError(event)"/> </s:RemoteObject> </fx:Declarations> <s:HGroup width="100%" paddingLeft="10" paddingRight="10" horizontalAlign="center" verticalAlign="middle"> <s:Label text="统计方式:" paddingLeft="10"/> <s:DropDownList id="tjfsDPDDL" width="175" dataProvider="{tjfsDP}" labelField="label" selectedIndex="0" change="tjfsDP_changeHandler(event)"/> <mx:Spacer width="10"/> <s:Label text="年份:"/> <s:DropDownList id="year" width="120" change="year_changeHandler(event)"/> <mx:Spacer width="100%"/> <s:Button label="查询" click="bt_find(event)"/> </s:HGroup> <s:HGroup id="chartHGroup" width="100%" height="100%" verticalAlign="middle" horizontalAlign="center"> <mx:Spacer width="150"/> <ilog:PieChart3D id="chart" dataProvider="{xmlData}" height="500" width="400" depth="10" depthGap="10" showDataTips="true" color="0xCECECE" rotationAngle="180"> <ilog:series> <ilog:PieSeries3D id="pieSeries3D" field="FAULTCOUNT" nameField="LABEL"> </ilog:PieSeries3D> </ilog:series> </ilog:PieChart3D> <mx:ControlBar id="chartCB" width="100%" verticalAlign="middle" horizontalAlign="center"> <mx:Legend dataProvider="{chart}" horizontalGap="100" width="100%" legendItemClass="gds.util.BigFontLegendItem"/> </mx:ControlBar> </s:HGroup> </mx:Module> java返回数据类型代码,后台分组sql查询出比例。
@SuppressWarnings("unchecked") public org.w3c.dom.Document statisticsFaultInfoByFaultType(String aYear) throws Exception { Element root = new Element("root"); // 根节点添加到文档中 Document doc = new Document(root); Map<String,String> aMap = new HashMap<String,String>(); aMap.put("aRecordYear",aYear); List<HashMap<String,String>> statisticsFaultInfoList = this .getSqlMapClientTemplate().queryForList( "statView.statisticsFaultInfoByFaultType",aMap); for (int i = 0; i < statisticsFaultInfoList.size(); i++) { Element statInforNodes = new Element("STATNODE"); HashMap<String,String> temp = statisticsFaultInfoList.get(i); String faultTypeID = temp.get("FAULTTYPEID"); Element faultTypeNode = new Element("FAULTTYPEID"); faultTypeNode.addContent(faultTypeID); String faultTypeName = temp.get("FAULTTYPENAME"); Element faultTypeNameNode = new Element("LABEL"); faultTypeNameNode.addContent(faultTypeName); String faultCount = temp.get("FAULTCOUNT"); Element faultCountNode = new Element("FAULTCOUNT"); faultCountNode.addContent(faultCount); statInforNodes.addContent(faultTypeNode); statInforNodes.addContent(faultTypeNameNode); statInforNodes.addContent(faultCountNode); root.addContent(statInforNodes); } DOMOutputter outputter = new DOMOutputter(); return outputter.output(doc); } 更多例子看:http://visudemos.ilog.com/webdemos/charts3d/charts3d.html (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |