Get selected index from ChartItemEvent
<?xml version="1.0"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml">
<mx:Script>
import mx.collections.ArrayCollection;
import mx.charts.events.ChartItemEvent;
[Bindable]
public var myArray:ArrayCollection = new ArrayCollection([
{Country:"A", GDP:1},
{Country:"B", GDP:6},
{Country:"C", GDP:4},
{Country:"D", GDP:2},
{Country:"E", GDP:3}
]);
[Bindable]
public var americanGDP:ArrayCollection = new ArrayCollection([
{Category:"X", GDPContribution:1},
{Category:"Y", GDPContribution:2},
{Category:"Z", GDPContribution:2}
]);
private function itemClickHandler(e:ChartItemEvent):void {
var selectedIndx:int = e.currentTarget.series.selectedIndex;
trace("selectedIndx: " + selectedIndx);
}
</mx:Script>
<mx:Panel title="Pie Chart">
<mx:PieChart id="myChart"
dataProvider="{myArray}"
showDataTips="true"
itemClick="itemClickHandler(event)"
selectionMode="single" >
<mx:series>
<mx:PieSeries id="ps1" field="GDP" nameField="Country" labelPosition="callout" selectable="true" />
</mx:series>
</mx:PieChart>
<mx:Legend dataProvider="{myChart}"/>
</mx:Panel>
</mx:Application>
Related examples in the same category