Flex3 DataGrid拖拽到ClumnChart動態(tài)顯示圖表實(shí)現(xiàn)代碼
更新時間:2013年01月29日 14:36:51 投稿:whsnow
Flex3 DataGrid拖拽到ClumnChart動態(tài)顯示圖表(支持多行同時拖拽,重復(fù)數(shù)據(jù)不重得添加,添加了圖表右鍵菜單)等等,感興趣的朋友可以了解下啊,或許對你有所幫助


支持多行同時拖拽,重復(fù)數(shù)據(jù)不重得添加,添加了圖表右鍵菜單.
復(fù)制代碼 代碼如下:
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" creationComplete="init()">
<mx:Script>
<![CDATA[
import mx.controls.Alert;
import mx.controls.DataGrid;
import mx.managers.DragManager;
import mx.core.UIComponent;
import mx.collections.ArrayCollection;
import mx.events.DragEvent;
//DataGrid的數(shù)據(jù)源
]);
//ColumnChart的數(shù)據(jù)源, 默認(rèn)為空
[Bindable]
private var chartData:ArrayCollection = new ArrayCollection();
[Bindable]
private var menu:ContextMenu = new ContextMenu();
private function init():void{
column.addEventListener(DragEvent.DRAG_ENTER,dragEnterHandle);
column.addEventListener(DragEvent.DRAG_DROP,dragdropHandle);
//初始化右鍵菜單
initMenu();
}
//初始化chart右鍵菜單
private function initMenu():void
{
var clear:ContextMenuItem = new ContextMenuItem("清空圖表");
menu.customItems.push(clear);
clear.addEventListener(ContextMenuEvent.MENU_ITEM_SELECT,clearAction);
}
//處理鼠標(biāo)右鍵事件
private function clearAction(event:ContextMenuEvent):void
{
this.chartData.removeAll();
}
private function dragEnterHandle(e:DragEvent):void{
DragManager.acceptDragDrop(e.currentTarget as UIComponent)
}
//拖拽放開后處理
private function dragdropHandle(e:DragEvent):void{
//往column chart的dataprovider中添加拖拽數(shù)據(jù)。
//如果只需要特定的數(shù)據(jù)進(jìn)入column chart,可以先做數(shù)據(jù)篩選。
var datas: Array = (e.dragInitiator as DataGrid).selectedItems;
for(var i:int = 0; i < datas.length; i ++)
{
//不包含已經(jīng)存在的數(shù)據(jù)再添加
if(!chartData.contains(datas[i]))
{
chartData.addItem(datas[i]);
}
}
}
]]>
</mx:Script>
<mx:DataGrid dragEnabled="true" dataProvider="{medalsAC}" x="192" y="52" allowMultipleSelection="true">
<mx:columns>
<mx:DataGridColumn dataField="Country" headerText="國家" />
<mx:DataGridColumn dataField="Gold" headerText="金牌"/>
<mx:DataGridColumn dataField="Silver" headerText="銀牌"/>
<mx:DataGridColumn dataField="Bronze" headerText="銅牌"/>
</mx:columns>
</mx:DataGrid>
<!-- 定義顏色 -->
<mx:SolidColor id="sc1" color="yellow" alpha=".8"/>
<mx:SolidColor id="sc2" color="0xCCCCCC" alpha=".6"/>
<mx:SolidColor id="sc3" color="0xFFCC66" alpha=".6"/>
<!-- 定義顏色 -->
<mx:Stroke id="s1" color="yellow" weight="2"/>
<mx:Stroke id="s2" color="0xCCCCCC" weight="2"/>
<mx:Stroke id="s3" color="0xFFCC66" weight="2"/>
<!--Column chart設(shè)置成能解析Country: "Russia", Gold: 27, Silver:27, Bronze: 38這樣的數(shù)據(jù)項(xiàng)-->
<mx:ColumnChart id="column" contextMenu="{menu}"
height="202"
width="402"
paddingLeft="5"
paddingRight="5"
showDataTips="true"
dataProvider="{chartData}"
x="192" y="215">
<!--設(shè)置水平軸-->
<mx:horizontalAxis>
<!--水平軸拖動數(shù)據(jù)到chart后的文字顯示-->
<mx:CategoryAxis categoryField="Country" />
</mx:horizontalAxis>
<!--設(shè)置柱子-->
<!--fill填充顏色,stroke邊框顏色-->
<mx:series>
<mx:ColumnSeries
xField="Country"
yField="Gold"
displayName="金牌"
fill="{sc1}"
stroke="{s1}"
/>
<mx:ColumnSeries
xField="Country"
yField="Silver"
displayName="銀牌"
fill="{sc2}"
stroke="{s2}"
/>
<mx:ColumnSeries
xField="Country"
yField="Bronze"
displayName="銅牌"
fill="{sc3}"
stroke="{s3}"
/>
</mx:series>
</mx:ColumnChart>
</mx:Application>
相關(guān)文章
Flex中實(shí)現(xiàn)對一個text渲染不同的字體顏色示例
本文為大家詳細(xì)介紹下Flex中如何實(shí)現(xiàn)對一個text渲染不同的字體顏色,具體的實(shí)現(xiàn)思路及代碼如下,有興趣的朋友可以參考下哈,希望對大家有所幫助2013-07-07
FLEX ArrayCollection刪除過濾的數(shù)據(jù)問題解決
ArrayCollection添加過濾器后,調(diào)用removeItemAt()是無法刪除的,下面有個不錯的解決方法,大家可以參考下2014-06-06
Flex中通過RadioButton進(jìn)行切換示例代碼
這篇文章主要介紹了Flex中通過RadioButton進(jìn)行切換示例代碼,需要的朋友可以參考下2014-02-02
Flex tree加虛線顯示效果并且替代原始圖標(biāo)
Flex tree修改默認(rèn)圖標(biāo)并且加虛線顯示效果,實(shí)在是看不下去那種巨丑無比的小箭頭+文件夾的顯示方式,具體實(shí)現(xiàn)如下,有此需求的朋友可以參考下,希望對家有所幫助2013-08-08
flex4 panel去掉標(biāo)題設(shè)置透明度效果代碼
首先:去掉Panel的標(biāo)題,其次:設(shè)置透明度這個說了也是啰嗦,大家都會,不過還是提一下吧,具體請祥看本文2013-05-05
flex壓縮圖片exif信息(作者/相機(jī))丟失問題解決
使用flex的jpegencoder對圖片進(jìn)行壓縮的時候,exif信息會丟失這一點(diǎn)確實(shí)令人郁悶啊,此問題應(yīng)當(dāng)如何解決呢?經(jīng)研究jpeg的文檔,最終解決這個問題,曬出來與大家分享希望可以幫助到你們2013-02-02
Flex設(shè)置LinkButton的背景色有思路有源碼
Flex中沒有設(shè)置LinkButton的背景色的屬性,可以直接通過調(diào)用樣式方法畫出LinkButton的背景色2014-08-08

