1 Reply Latest reply on Dec 15, 2008 12:58 PM by matthew horn

    Handling click event on a slice of PieChart

    glen08 Level 1
      I need to handle the event of click on the slices of a PieChart and retrieve the data associated with that slice.
      The "click" and "itemClick" events with PieChart was not triggered. What event should I handle?

        • 1. Re: Handling click event on a slice of PieChart
          matthew horn Level 3
          Use the pie chart's change event. That event is dispatched when the selection changes. Here's an example:

          <?xml version="1.0" ?>
          <!-- charts/SimpleSelection.mxml -->
          <mx:Application xmlns:mx=" http://www.adobe.com/2006/mxml" creationComplete="srv_budget.send()">

          <mx:HTTPService id="srv_budget" url=" http://aspexamples.adobe.com/chart_examples/budget-xml.aspx"/>
          <!-- To see data in an HTML table, go to http://aspexamples.adobe.com/chart_examples/budget.aspx -->

          <mx:Script>
          <![CDATA[
          import mx.collections.ArrayCollection;

          private function handleChange(event:Event, ta:TextArea):void {
          var allSeries:Array = event.currentTarget.series;
          ta.text = "";
          for (var i:int=0; i<allSeries.length; i++) {
          ta.text += "\n" + allSeries .id +
          " Selected Items: " + allSeries
          .selectedIndices;
          }
          }
          ]]>
          </mx:Script>
          <mx:VBox>

          <mx:Panel title="Pie Chart">
          <mx:HBox>
          <mx:PieChart id="myPieChart"
          height="225"
          dataProvider="{srv_budget.lastResult.data.result}"
          showDataTips="true"
          selectionMode="multiple"
          change="handleChange(event, textArea2)"
          >
          <mx:series>
          <mx:PieSeries
          id="pieSeries1"
          field="amount"
          nameField="item"
          labelPosition="callout"
          />
          </mx:series>
          </mx:PieChart>
          <mx:VBox width="370" height="200">
          <mx:Label text="Click a chart's item to select it." />
          <mx:Label text="Click and drag to select multiple items." />
          <mx:Label text="Selection Changed Event:" />
          <mx:TextArea id="textArea2" height="100" width="213"/>
          </mx:VBox>
          </mx:HBox>
          <mx:Legend dataProvider="{myPieChart}"/>
          </mx:Panel>
          </mx:VBox>

          </mx:Application>


          hth,
          matt horn
          flex docs