国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 網(wǎng)站 > WEB開發(fā) > 正文

16.10.拖曳圖表中的項目

2024-04-27 13:52:23
字體:
供稿:網(wǎng)友
16.10.1. 問題
我想從一個數(shù)據(jù)源里拖曳項目到圖表中。
16.10.2. 解決辦法
覆蓋圖表組件的dragEnterHandler()和dragDropHandler()方法則可創(chuàng)建一個可拖曳的圖表。
16.10.3. 討論
在flex 框架中圖表的拖曳功能和其他組件的拖曳功能是相同。父類組件為mouseMove 事件定義一個處理器,為dragDrop 事件定義一個處理器來接收被拖曳的數(shù)據(jù)。在下面的例子中,兩個餅圖的dragEnabled 和dropEnabled 屬性都設(shè)置為true,分別有單獨的ArrayCollections作為各自的數(shù)據(jù)提供器。當(dāng)數(shù)據(jù)從一個組件中被拖出,它就會從組件中脫離然后被添加到其他的數(shù)據(jù)提供器中。
+展開
-XML
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"xmlns:cookbook="oreilly.cookbook.*">
<mx:Script>
<![CDATA[
import mx.events.DragEvent;
import mx.charts.PieChart;
import mx.core.IUIComponent;
import mx.core.DragSource;
import mx.containers.Panel;
import mx.managers.DragManager;
import mx.collections.ArrayCollection;
[Bindable]
private var masterArrColl:ArrayCollection = new ArrayCollection([
"name":"C Ronaldo""sog":128, "goals":20, "games":33 },
"name":"A Adebayor""sog":128, "goals":20, "games":35 },
"name":"F Torres""sog":98, "goals":18, "games":32 },
"name":"W Rooney""sog":89, "goals":17, "games":34 },
"name":"D Drogba""sog":114, "goals":16, "games":31 }]);
[Bindable]
private var subColl:ArrayCollection = new ArrayCollection([
"name":"C Ronaldo""sog":128, "goals":20, "games":33 },
"name":"A Adebayor""sog":128, "goals":20, "games":35
}]);
// Initializes the drag-and-drop operation.
private function
mouseMoveHandler(event:MouseEvent):void {
event.preventDefault();
// Get the drag initiator component from the event object.
//從事件對象中取得拖曳事件初始化組件
var dragInitiator:PieChart = PieChart(event.currentTarget);
// Create a DragSource object.
//創(chuàng)建一個DragSource對象
var ds:DragSource = new DragSource();
//make sure that the chart has a selected item
//確定圖表的某個元素是處于選擇狀態(tài)中
if(dragInitiator.selectedChartItem == nullreturn;
// Call the DragManager doDrag() method to start the drag.
//調(diào)用DragManager doDrag()方法開始拖曳事件
DragManager.doDrag(dragInitiator, ds, event);
}
//mouseMoveHandler()方法用于傳遞dragInitiator,該組件向DragManager.doDrag
//管理器發(fā)出拖 動事件和DataSource 對象(該例子沒有用到),鼠標(biāo)事件也被激活。
//mouseMoveHandler()方法
// Called if the target accepts the dragged object and the user
// releases the mouse button while over the Canvas container.
//目標(biāo)接受dragged對象以及用戶在Canvas容器中釋放鼠標(biāo)就調(diào)用以下方法:
private function dragDropHandler(event:DragEvent):void {
// Get the selected data from the chart
//取得圖表中被選的元素
var index:Number = (event.dragInitiator as PieChart).selectedChartItem.index;
(event.currentTarget as PieChart).dataProvider.addItem((event.dragInitiator as PieChart).dataProvider.getItemAt(index));
(event.dragInitiator as PieChart).dataProvider.removeItemAt(index);
}
//對象是首次添加到dragEvent 的currentTarget 的數(shù)據(jù)提供器中,就是添加到了餅圖上。從
//ragEvent.dragInitiator 中移出的數(shù)據(jù)(以及相應(yīng)的對象),也從餅圖中移除了。

]]>
</mx:Script>
<mx:PieChart dataProvider="{subColl}selectionMode="single"
dragEnabled="truedropEnabled="true"
mouseMove="mouseMoveHandler(event)"
dragDrop="dragDropHandler(event)">

<mx:series>
<mx:PieSeries field="goalsnameField="name"
labelField="namelabelPosition="callout"
selectable="true"/>

</mx:series>
</mx:PieChart>
<mx:PieChart dataProvider="{masterArrColl}dragEnabled="true"
dropEnabled="trueselectionMode="single"
mouseMove="mouseMoveHandler(event)"
dragDrop="dragDropHandler(event)">

<mx:series>
<mx:PieSeries field="goalsnameField="name"
labelField="namelabelPosition="callout"
selectable="true"/>

</mx:series>
</mx:PieChart>
</mx:Application>
發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 益阳市| 吉木乃县| 远安县| 东兴市| 崇阳县| 顺平县| 沭阳县| 天峻县| 唐山市| 瓦房店市| 东明县| 莲花县| 望都县| 杂多县| 岳西县| 大厂| 胶南市| 电白县| 特克斯县| 清河县| 锡林浩特市| 商丘市| 固安县| 额济纳旗| 门头沟区| 齐河县| 得荣县| 白朗县| 依兰县| 安溪县| 中牟县| 新野县| 宜黄县| 吉林市| 朝阳市| 呼伦贝尔市| 观塘区| 金乡县| 武城县| 中江县| 鄱阳县|