Flex3 DataGrid拖拽到ClumnChart动态显示图表
Flex
#
datagrid #
clumnchart #
拖拽2014-04-10 09:32
以下代码支持多行同时拖拽,重复数据不重得添加,添加了图表右键菜单等等。
01 | <?xml version= "1.0" encoding= "utf-8" ?> |
03 | creationComplete= "init()" > |
05 | <![CDATA[ import mx.controls.Alert; import mx.controls.DataGrid; import |
06 | mx.managers.DragManager; import mx.core.UIComponent; import mx.collections.ArrayCollection; |
07 | import mx.events.DragEvent; |
08 | ew ArrayCollection( [ { Country: "美国" , Gold: 35 , Silver: 39 , Bronze: 29 |
09 | }, { Country: "中国" , Gold: 99 , Silver: 17 , Bronze: 14 }, { Country: "日本" , |
10 | Gold: 32 , Silver: 27 , Bronze: 38 }, { Country: "韩国" , Gold: 27 , Silver: 27 , |
11 | Bronze: 2 }, { Country: "新加坡" , Gold: 55 , Silver: 27 , Bronze: 63 }, { Country: |
12 | "朝鲜" , Gold: 11 , Silver: 21 , Bronze: 16 }, { Country: "马来西亚" , Gold: 7 , Silver: 14 , |
13 | Bronze: 77 }, { Country: "澳洲" , Gold: 0 , Silver: 12 , Bronze: 11 } ]); |
14 | 默认为空 [Bindable] private var chartData:ArrayCollection=n ew ArrayCollection(); |
15 | [Bindable] private var menu:ContextMenu=n ew ContextMenu(); |
16 | private function init(): void { column.addEventListener(DragEvent.DRAG_ENTER,dragEnterHandle); |
17 | column.addEventListener(DragEvent.DRAG_DROP,dragdropHandle); |
19 | ew ContextMenuItem( "清空图表" ); menu.customItems.push(clear); clear.addEventListener(ContextMenuEvent.MENU_ITEM_SELECT,clearAction); |
21 | { this .chartData.removeAll(); } |
22 | private function dragEnterHandle(e:DragEvent): void { DragManager.acceptDragDrop(e.currentTarget |
25 | var datas: Array =( e.dragInitiator as DataGrid).selectedItems; for ( var |
26 | i: int = 0 ; i < datas.length; i ++) { |
27 | { chartData.addItem(datas[i]); } } } ]]> |
29 | <mx:DataGrid dragEnabled= "true" dataProvider= "{medalsAC}" x= "192" y= "52" |
30 | allowMultipleSelection= "true" > |
32 | <mx:DataGridColumn dataField= "Country" headerText= "国家" /> |
33 | <mx:DataGridColumn dataField= "Gold" headerText= "金牌" /> |
34 | <mx:DataGridColumn dataField= "Silver" headerText= "银牌" /> |
35 | <mx:DataGridColumn dataField= "Bronze" headerText= "铜牌" /> |
39 | <mx:SolidColor id= "sc1" color= "yellow" alpha= ".8" /> |
40 | <mx:SolidColor id= "sc2" color= "0xCCCCCC" alpha= ".6" /> |
41 | <mx:SolidColor id= "sc3" color= "0xFFCC66" alpha= ".6" /> |
43 | <mx:Stroke id= "s1" color= "yellow" weight= "2" /> |
44 | <mx:Stroke id= "s2" color= "0xCCCCCC" weight= "2" /> |
45 | <mx:Stroke id= "s3" color= "0xFFCC66" weight= "2" /> |
46 | <!--Column chart设置成能解析Country: "Russia" , Gold: 27 , Silver: 27 , Bronze: |
48 | <mx:ColumnChart id= "column" contextMenu= "{menu}" height= "202" width= "402" |
49 | paddingLeft= "5" paddingRight= "5" showDataTips= "true" dataProvider= "{chartData}" |
53 | <!--水平轴拖动数据到chart后的文字显示--> |
54 | <mx:CategoryAxis categoryField= "Country" /> |
57 | <!--fill填充颜色,stroke边框颜色 http: |
59 | <mx:ColumnSeries xField= "Country" yField= "Gold" displayName= "金牌" fill= "{sc1}" |
61 | <mx:ColumnSeries xField= "Country" yField= "Silver" displayName= "银牌" fill= "{sc2}" |
63 | <mx:ColumnSeries xField= "Country" yField= "Bronze" displayName= "铜牌" fill= "{sc3}" |
相关文章