<?xml version="1.0" encoding="utf-8"?>
<!-- http://blog.flexexamples.com/2008/09/26/setting-a-custom-label-function-on-a-piechart-in-flex/ -->
<mx:Application name="PieSeries_labelFunction_test"
        xmlns:mx="http://www.adobe.com/2006/mxml"
        layout="vertical"
        verticalAlign="middle"
        backgroundColor="white"
        initialize="init();">

    <mx:Script>
        <![CDATA[
            import mx.charts.Legend;
            import mx.charts.PieChart;
            import mx.charts.chartClasses.Series;
            import mx.charts.series.PieSeries;
            import mx.collections.XMLListCollection;
            import mx.containers.ControlBar;
            import mx.containers.Panel;
            import mx.containers.TileDirection;
            import mx.utils.StringUtil;

            private var dp:XMLListCollection;
            private var legend:Legend;
            private var panel:Panel;
            private var pieChart:PieChart;
            private var pieSeries:PieSeries;

            private function init():void {
                var productsXML:XML = <products>
                            <product label="Product 1" data="3" />
                            <product label="Product 2" data="1" />
                            <product label="Product 3" data="4" />
                            <product label="Product 4" data="1" />
                            <product label="Product 5" data="5" />
                            <product label="Product 6" data="9" />
                        </products>;

                dp = new XMLListCollection(productsXML.product);

                pieSeries = new PieSeries();
                pieSeries.field = "@data";
                pieSeries.nameField = "@label";
                pieSeries.setStyle("labelPosition", "callout");
                pieSeries.labelFunction = pieSeries_labelFunc;

                pieChart = new PieChart();
                pieChart.dataProvider = dp;
                pieChart.showDataTips = false;
                pieChart.percentWidth = 100;
                pieChart.percentHeight = 100;
                pieChart.series = [pieSeries];

                legend = new Legend();
                legend.dataProvider = pieChart;
                legend.direction = TileDirection.HORIZONTAL;
                legend.setStyle("horizontalGap", 100);
                legend.percentWidth = 100;

                var controlBar:ControlBar = new ControlBar();
                controlBar.percentWidth = 100;
                controlBar.addChild(legend);

                panel = new Panel();
                panel.styleName = "opaquePanel";
                panel.percentWidth = 100;
                panel.percentHeight = 100;
                panel.addChild(pieChart);
                panel.addChild(controlBar);
                addChild(panel);
            }

            private function pieSeries_labelFunc(item:Object, field:String, index:Number, percentValue:Number):String {
                return StringUtil.substitute("{0} ({1}%)",
                            item.@label,
                            percentValue.toFixed(1));
            }
        ]]>
    </mx:Script>

</mx:Application>