1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88
|
<?xml version="1.0" encoding="utf-8"?>
<s:Group xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx" width="400" height="300"
creationComplete="init()" >
<fx:Declarations>
<!-- Placer ici les éléments non visuels (services et objets de valeur, par exemple). -->
</fx:Declarations>
<fx:Script>
<![CDATA[
import mx.charts.ChartItem;
import mx.charts.events.ChartItemEvent;
import mx.collections.ArrayCollection;
import mx.events.CollectionEvent;
[Bindable]
private var provider:ArrayCollection = new ArrayCollection([
{x: 1, y: 5},
{x: 2, y: 10},
{x: 3, y: 5},
{x: 4, y: 10},
{x: 5, y: 5},
{x: 6, y: 10}
]);
[Bindable]
private var idx:Number;
private function init():void{
chart.addEventListener(ChartItemEvent.ITEM_CLICK,onItemClicDown);
chart.addEventListener(MouseEvent.MOUSE_UP,onItemClicUp);
}
private function onItemClicDown(event:ChartItemEvent):void{
var item:Object = event.hitData.item;
idx = provider.getItemIndex(item);
chart.addEventListener(MouseEvent.MOUSE_MOVE,onItemMouve);
}
private function onItemMouve(event:MouseEvent):void{
var item:Object = provider.getItemAt(idx);
var tmpCollection:ArrayCollection = provider;
var p:Point = new Point(chart.mouseX,chart.mouseY);
var d:Array = serie.localToData(p);
item.y = d[1];
tmpCollection.setItemAt(item,idx);
provider = tmpCollection;
}
private function onItemClicUp(event:MouseEvent):void{
chart.removeEventListener(MouseEvent.MOUSE_MOVE,onItemMouve);
}
]]>
</fx:Script>
<s:Panel>
<mx:LineChart id="chart" >
<mx:series>
<mx:LineSeries
dataProvider="{provider}"
xField="x"
yField="y"
id="serie"
itemRenderer="mx.charts.renderers.CircleItemRenderer">
</mx:LineSeries>
</mx:series>
</mx:LineChart>
</s:Panel>
</s:Group> |
Partager