Exploding all wedges in a Flex PieChart control using the explodeRadius property

by Peter deHaan on November 10, 2007

in Charting, PieChart, PieSeries

The following example shows how you can explode all wedges in a PieChart at once by using the explodeRadius property, as seen in the following snippet:

<mx:PieChart dataProvider="{dp.product}" height="100%" width="100%">
    <mx:series>
        <mx:PieSeries field="@data" labelPosition="callout">
            <mx:explodeRadius>0.2</mx:explodeRadius>
            <mx:filters>
                <mx:Array />
            </mx:filters>
        </mx:PieSeries>
    </mx:series>
</mx:PieChart>

If you want to explode individual wedges, simply use the perWedgeExplodeRadius property.

Full code after the jump.

View MXML

<?xml version="1.0" encoding="utf-8"?>
<!-- http://blog.flexexamples.com/2007/11/10/exploding-all-wedges-in-a-flex-piechart-control-using-the-exploderadius-property/ -->
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
        layout="vertical"
        verticalAlign="middle"
        backgroundColor="white">

    <mx:Script>
        <![CDATA[
            import mx.events.SliderEvent;

            private function setExplodeRadius(evt:SliderEvent):void {
                pieSeries.explodeRadius = evt.value;
            }
        ]]>
    </mx:Script>

    <mx:XML id="dp">
        <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>
    </mx:XML>

    <mx:ApplicationControlBar dock="true">
        <mx:Form styleName="plain">
            <mx:FormItem label="explodeRadius:">
                <mx:HSlider id="slider"
                        minimum="0.0"
                        maximum="0.8"
                        value="0.2"
                        liveDragging="true"
                        showTrackHighlight="true"
                        snapInterval="0.1"
                        tickInterval="0.1"
                        change="setExplodeRadius(event);" />
            </mx:FormItem>
        </mx:Form>
    </mx:ApplicationControlBar>

    <mx:PieChart id="pieChart"
            dataProvider="{dp.product}"
            height="100%"
            width="100%">
        <mx:series>
            <mx:PieSeries id="pieSeries"
                    field="@data"
                    labelPosition="callout">
                <mx:explodeRadius>0.2</mx:explodeRadius>
                <mx:filters>
                    <mx:Array />
                </mx:filters>
            </mx:PieSeries>
        </mx:series>
    </mx:PieChart>

</mx:Application>

View source is enabled in the following example.

{ 4 comments… read them below or add one }

1 ÐâŖк6 November 21, 2007 at 9:13 am

Thanks again, my friend.
You are really helping me a lot.
Greetings from Costa Rica.

Reply

2 John Omesili July 3, 2009 at 2:36 pm

I bring greetings to from Nigeria, your blog has been a very insight to Flex.
At the moment , I cant get my piechart’s legend direction to dispay horizontally. Do hope i find a solution though. Anyways thanks a Gazillion

Reply

3 Paras July 10, 2009 at 9:36 am

Peter – you are legend. Very useful blog. Keep up the good work.

Reply

4 Nathan October 30, 2009 at 3:35 am

Hi Peter,

Thanks for the stuffs.

How to explode only one Wedge per user click??

Please share the code.

Reply

Leave a Comment

Sorry, this blog is terrible at eating HTML comments.
If you're pasting any HTML/XML/MXML code, you need to convert your < characters to &lt; and your > characters to &gt; .

You can 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

Previous post:

Next post: