Avg. Rating 3.0

Problem

You want to set a custom width and height for the markers on a Flex chart's legend.

Solution

The following example shows how you can set the marker width and marker height on a Flex Legend control by setting the markerWidth and markerHeight styles.

Detailed explanation

<?xml version="1.0" encoding="utf-8"?>
<!-- http://blog.flexexamples.com/2008/09/28/setting-the-marker-width-and-height-on-a-legend-control-in-flex/ -->
<mx:Application name="Legend_markerHeight_test"
        xmlns:mx="http://www.adobe.com/2006/mxml"
        layout="vertical"
        verticalAlign="middle"
        backgroundColor="white">

    <mx:XMLListCollection id="dp">
        <mx:source>
            <mx:XMLList>
                <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" />
            </mx:XMLList>
        </mx:source>
    </mx:XMLListCollection>

    <mx:ApplicationControlBar dock="true">
        <mx:Form styleName="plain">
            <mx:FormItem label="markerWidth:">
                <mx:HSlider id="markerWSlider"
                        minimum="5"
                        maximum="15"
                        value="10"
                        snapInterval="1"
                        tickInterval="1"
                        liveDragging="true" />
            </mx:FormItem>
            <mx:FormItem label="markerHeight:">
                <mx:HSlider id="markerHSlider"
                        minimum="5"
                        maximum="15"
                        value="10"
                        snapInterval="1"
                        tickInterval="1"
                        liveDragging="true" />
            </mx:FormItem>
        </mx:Form>
    </mx:ApplicationControlBar>

    <mx:Panel id="panel"
            styleName="opaquePanel"
            width="100%"
            height="100%">
        <mx:PieChart id="pieChart"
                dataProvider="{dp}"
                showDataTips="true"
                height="100%"
                width="100%">
            <mx:series>
                <mx:PieSeries id="pieSeries"
                        field="@data"
                        nameField="@label"
                        filters="[]" />
            </mx:series>
        </mx:PieChart>
        <mx:ControlBar>
            <mx:Legend id="legend"
                    dataProvider="{pieChart}"
                    direction="horizontal"
                    horizontalGap="100"
                    markerWidth="{markerWSlider.value}"
                    markerHeight="{markerHSlider.value}" />
        </mx:ControlBar>
    </mx:Panel>

</mx:Application>

For more information, see "Setting the marker width and height on a Legend control in Flex" at FlexExamples.com.

 

Report abuse

Related recipes