ADOBE FLEX 3
Adobe Flex 3 Data Visualization Developer Guide
211
In addition to the ChartEvent and ChartItemEvent classes, there is also the LegendMouseEvent. This class defines
events that are broadcast when the user clicks on legend items or mouses over them.
About chart events
Chart events are triggered when the user clicks or double-clicks the mouse button while the mouse pointer is over a
chart control, but not over a chart item in that chart control. These events are dispatched only if the hit data set is
empty.
Chart events are of type ChartEvent. Because ChartEvent events are part of the charts package, and not part of the
events package, you must import the appropriate classes in the mx.charts.events package to use a ChartEvent event.
The following example logs a ChartEvent when you click or double-click the chart control, but only if you are not
over a chart item or within it’s range, as determined by its
mouseSensitivity property.
<?xml version="1.0"?>
<!-- charts/BasicChartEvent.mxml -->
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml">
<mx:Script><![CDATA[
import mx.collections.ArrayCollection;
import mx.charts.events.ChartEvent;
[Bindable]
public var expenses:ArrayCollection = new ArrayCollection([
{Month:"January", Profit:2000, Expenses:1500, Amount:450},
{Month:"February", Profit:1000, Expenses:200, Amount:600},
{Month:"March", Profit:1500, Expenses:500, Amount:300},
{Month:"April", Profit:500, Expenses:300, Amount:500},
{Month:"May", Profit:1000, Expenses:450, Amount:250},
{Month:"June", Profit:2000, Expenses:500, Amount:700}
]);
private function chartEventHandler(event:ChartEvent):void {
/*
The ChartEvent will only be dispatched if the mouse is _not_ over a
chart item or if it is outside of the range defined by the
mouseSensitivity property.
*/
ta1.text += "Event of type " + event.type + " was triggered.\n";
}
]]></mx:Script>
<mx:Style>
Panel {
paddingLeft:5;
paddingRight:5;
paddingTop:5;
paddingBottom:5;
}
</mx:Style>
<mx:Panel title="Chart click events">
<mx:HBox>
<mx:PlotChart id="myChart"
dataProvider="{expenses}"
itemRollOut
Broadcast when the closest data point under the mouse pointer changes.
itemRollOver
Broadcast when the user moves the mouse pointer over a new data point.
Chart data event type Description

Get ADOBE® FLEX® 3: ADVANCED DATA VISUALIZATION DEVELOPER GUIDE now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.