1 Reply Latest reply on Apr 14, 2011 1:19 PM by digsafe

    how to retrieve pie chart wedge id

    digsafe

      Hi.

      I'm trying to figure out how to get an id or index of a specific wedge from a pie chart

      I think I'm close. I just need to find the right path to the wedge id.

      This is what I have so far.

       

      <fx:Script><![CDATA[
             
              import mx.charts.events.ChartItemEvent;
            
              private function itemClickHandler(e:ChartItemEvent):void {
                  var selectedIndx:String= e.currentTarget.series.index; //<--returns null
              
              }
          ]]></fx:Script>

       

      <s:VGroup>
              <mx:PieChart width="220" height="220" id="piechart1"
                           dataProvider="{srv.lastResult.AAFunds.fundName}"
                           itemClick="itemClickHandler(event)"
                           >
                  <mx:series>
                      <mx:PieSeries  displayName="pie series 1" />
                  </mx:series>
              </mx:PieChart>
             
          </s:VGroup>

        • 1. Re: how to retrieve pie chart wedge id
          digsafe Level 1

          Figured it out.

          Here is a simple example;

           

          <?xml version="1.0" encoding="utf-8"?>
          <!-- http://blog.flexexamples.com/2007/11/15/displaying-a-pieseries-items-data-when-a-user-clic ks-an-item-in-a-flex-piechart-control/ -->
          <s:Application
              xmlns:fx="http://ns.adobe.com/mxml/2009"
              xmlns:mx="library://ns.adobe.com/flex/mx"
              xmlns:s="library://ns.adobe.com/flex/spark"
              >
             
              <fx:Declarations>
              </fx:Declarations>
             
              <fx:Script>
                  <![CDATA[
                      import mx.charts.series.items.PieSeriesItem;
                      import mx.charts.events.ChartItemEvent;
                     
                      [Bindable]
                      public var chartDP:Array = [
                         
                          {wedgeName:'Pie wedge 1', percent:45 },
                          {wedgeName:'Pie wedge 2', percent:25},
                          {wedgeName:'Pie wedge 5', percent:22},
                          {wedgeName:'Pie wedge 4', percent:8}
                      ];
                     
                      private function pieChart_itemClick(evt:ChartItemEvent):void {
                          var psi:PieSeriesItem = evt.hitData.chartItem as PieSeriesItem;
                          myTextArea.text += "\rwedgeName: "+psi.item.wedgeName+" percent: "+ psi.item.percent;
                          }
                  ]]>
              </fx:Script>
             
          <s:VGroup>
              <mx:PieChart id="pieChart"
                           dataProvider="{chartDP}"
                           itemClick="pieChart_itemClick(event);"
                           showDataTips="false"
                           height="300"
                           width="300">
                  <mx:series>
                      <mx:PieSeries id="pieSeries"
                                    field="percent">
                         
                      </mx:PieSeries>
                  </mx:series>
              </mx:PieChart>
             
              <s:TextArea id="myTextArea"  y="82" width="350" height="250" />
          </s:VGroup>
             
          </s:Application>