The following example shows you how to use the innerRadius style to create donut shaped pie charts in Flex.

Full code after the jump.

View MXML

<?xml version="1.0" encoding="utf-8"?>
<!-- http://blog.flexexamples.com/2007/10/13/creating-donut-shaped-pie-charts-using-the-innerradius-style/ -->
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
        layout="vertical"
        verticalAlign="middle"
        backgroundColor="white">

    <mx:Script>
        <![CDATA[
            private function labelFunc(item:Object, field:String, index:Number, percentValue:Number):String {
                return item.name + ": " + '\n' + "AVG: " + item.avg;
            }
        ]]>
    </mx:Script>

    <mx:ArrayCollection id="arrColl">
        <mx:source>
            <mx:Array>
                <mx:Object name="R Winn" obp=".353" slg=".445" avg=".300" />
                <mx:Object name="P Feliz" obp=".290" slg=".418" avg=".253" />
                <mx:Object name="O Vizquel" obp=".305" slg=".316" avg=".246" />
                <mx:Object name="B Molina" obp=".298" slg=".433" avg=".276" />
                <mx:Object name="R Durham" obp=".295" slg=".343" avg=".218" />
            </mx:Array>
        </mx:source>
    </mx:ArrayCollection>

    <mx:ApplicationControlBar dock="true">
        <mx:Label text="innerRadius:" />
        <mx:HSlider id="slider"
                minimum="0"
                maximum="0.5"
                liveDragging="true" />
    </mx:ApplicationControlBar>

    <mx:PieChart id="chart"
            height="100%"
            width="100%"
            innerRadius="{slider.value}"
            showDataTips="true"
            dataProvider="{arrColl}" >
        <mx:series>
            <mx:PieSeries labelPosition="callout"
                    field="avg"
                    labelFunction="labelFunc">
                <mx:calloutStroke>
                    <mx:Stroke weight="0"
                            color="0x888888"
                            alpha="100"/>
                </mx:calloutStroke>
                <mx:radialStroke>
                    <mx:Stroke weight="0"
                            color="#FFFFFF"
                            alpha="20"/>
                </mx:radialStroke>
                <mx:stroke>
                    <mx:Stroke color="0"
                            alpha="20"
                            weight="2"/>
                </mx:stroke>
            </mx:PieSeries>
        </mx:series>
    </mx:PieChart>

</mx:Application>

View source is enabled in the following example.

 
Tagged with:
 
About The Author

Peter deHaan

Peter deHaan currently works for Adobe on the Flex SDK QA team. While not working on Flex, Flash, and ColdFusion applications, Peter enjoys making up bios and writing in 3rd person. Peter's rarely updated blog can be found at blogs.adobe.com/pdehaan/, actionscriptexamples.com, airexamples.com, and coldfusionexamples.com.

3 Responses to Creating donut shaped Pie charts using the innerRadius style

  1. The labels don’t seem to be in the correct place in case of mulitple doughnut series :(

  2. peterd says:

    Tom Van den Eynde,

    Can you please file a bug (with a simple test case) at http://bugs.adobe.com/flex/?

    Thanks,
    Peter

    PS: If you post the bug number here, maybe a few of us can vote and/or subscribe to the issue.

  3. The bug was logged more than half a year ago (https://bugs.adobe.com/jira/browse/FLEXDMV-1643). Sometimes I get the impression that the Flex components don’t get the priority they deserve…

Leave a Reply

Your email address will not be published.

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="">

Anti-Spam Protection by WP-SpamFree