佳木斯湛栽影视文化发展公司

主頁(yè) > 知識(shí)庫(kù) > Flex3 DataGrid拖拽到ClumnChart動(dòng)態(tài)顯示圖表實(shí)現(xiàn)代碼

Flex3 DataGrid拖拽到ClumnChart動(dòng)態(tài)顯示圖表實(shí)現(xiàn)代碼

熱門(mén)標(biāo)簽:網(wǎng)站文章發(fā)布 服務(wù)器配置 智能手機(jī) 檢查注冊(cè)表項(xiàng) 美圖手機(jī) 鐵路電話系統(tǒng) 呼叫中心市場(chǎng)需求 銀行業(yè)務(wù)

支持多行同時(shí)拖拽,重復(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ù)源
[Bindable]
private var medalsAC:ArrayCollection = new ArrayCollection( [
{ Country: "美國(guó)", Gold: 35, Silver:39, Bronze: 29 },
{ Country: "中國(guó)", Gold: 99, Silver:17, Bronze: 14 },
{ Country: "日本", Gold: 32, Silver:27, Bronze: 38 },
{ Country: "韓國(guó)", Gold: 27, Silver:27, Bronze: 2 },
{ Country: "新加坡", Gold: 55, Silver:27, Bronze: 63 },
{ Country: "朝鮮", Gold: 11, Silver:21, Bronze: 16 },
{ Country: "馬來(lái)西亞", Gold: 7, Silver:14, Bronze: 77 },
{ Country: "澳洲", Gold: 0, Silver:12, Bronze: 11 }
]);
//ColumnChart的數(shù)據(jù)源, 默認(rèn)為空
[Bindable]
private var chartData:ArrayCollection = new ArrayCollection();
[Bindable]
private var menu:ContextMenu = new ContextMenu();
//讓columnChart監(jiān)聽(tīng)拖拽事件
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("清空?qǐng)D表");
menu.customItems.push(clear);
clear.addEventListener(ContextMenuEvent.MENU_ITEM_SELECT,clearAction);
}
//處理鼠標(biāo)右鍵事件
private function clearAction(event:ContextMenuEvent):void
{
this.chartData.removeAll();
}
//因?yàn)橹挥蠨ataGrid推拽,所以直接允許,如果界面上有多個(gè)控件監(jiān)聽(tīng)拖拽事件,需要判斷后允許正確的數(shù)據(jù)進(jìn)入
private function dragEnterHandle(e:DragEvent):void{
DragManager.acceptDragDrop(e.currentTarget as UIComponent)
}
//拖拽放開(kāi)后處理
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="國(guó)家" />
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>
!--水平軸拖動(dòng)數(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>

您可能感興趣的文章:
  • Flex DataGrid DataGridColumn數(shù)據(jù)顏色多樣化-類(lèi)型替換
  • Flex中讓鼠標(biāo)移至AdvancedDataGrid的行上不自動(dòng)修改顯示效果
  • Flex動(dòng)態(tài)生成可編輯的DataGrid具體實(shí)現(xiàn)代碼

標(biāo)簽:樂(lè)山 上海 長(zhǎng)治 滄州 紅河 河南 沈陽(yáng) 新疆

巨人網(wǎng)絡(luò)通訊聲明:本文標(biāo)題《Flex3 DataGrid拖拽到ClumnChart動(dòng)態(tài)顯示圖表實(shí)現(xiàn)代碼》,本文關(guān)鍵詞  ;如發(fā)現(xiàn)本文內(nèi)容存在版權(quán)問(wèn)題,煩請(qǐng)?zhí)峁┫嚓P(guān)信息告之我們,我們將及時(shí)溝通與處理。本站內(nèi)容系統(tǒng)采集于網(wǎng)絡(luò),涉及言論、版權(quán)與本站無(wú)關(guān)。
  • 相關(guān)文章
  • 收縮
    • 微信客服
    • 微信二維碼
    • 電話咨詢(xún)

    • 400-1100-266
    武义县| 遂宁市| 东至县| 宾阳县| 石阡县| 辉县市| 南岸区| 南阳市| 任丘市| 红桥区| 思南县| 连山| 五大连池市| 济源市| 瑞安市| 卓尼县| 徐汇区| 镇远县| 本溪| 手游| 东丰县| 扎兰屯市| 寿光市| 万盛区| 西畴县| 平塘县| 三明市| 石楼县| 天祝| 永川市| 青岛市| 华安县| 芷江| 枣强县| 钦州市| 文成县| 安福县| 霍城县| 额尔古纳市| 剑河县| 左贡县|