adjust bar width in barchart by setting columnWidthRatio

adjust bar width in barchart by setting columnWidthRatio

Postby haretu » Mon Mar 21, 2011 3:02 pm

Adobe flex

This sample shows how to adjust bar width in barchart by setting columnWidthRatio

Code: Select all
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
        layout="vertical"
        verticalAlign="middle"
        backgroundColor="white" viewSourceURL="srcview/index.html">

    <mx:Script>
        <![CDATA[
            import mx.charts.chartClasses.IAxis;

            private function linearAxis_labelFunc(item:Object, prevValue:Object, axis:IAxis):String {
                return numberFormatter.format(item);
            }
        ]]>
    </mx:Script>

    <mx:NumberFormatter id="numberFormatter" precision="3" />

    <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="columnWidthRatio:" />
        <mx:HSlider id="slider"
                minimum="0.1"
                maximum="0.9"
                value="0.1"
                liveDragging="true"
                snapInterval="0.1"
                tickInterval="0.1" />
    </mx:ApplicationControlBar>

    <mx:ColumnChart id="columnChart"
            showDataTips="true"
            dataProvider="{arrColl}"
            columnWidthRatio="{slider.value}"
            width="100%"
            height="100%">

        <mx:horizontalAxis>
            <mx:CategoryAxis id="ca"
                    categoryField="name" />
        </mx:horizontalAxis>

        <mx:verticalAxis>
            <mx:LinearAxis baseAtZero="false"
                    minimum="0.200"
                    maximum="0.310"
                    labelFunction="linearAxis_labelFunc" />
        </mx:verticalAxis>

        <mx:horizontalAxisRenderers>
            <mx:AxisRenderer axis="{ca}"
                    canDropLabels="false" />
        </mx:horizontalAxisRenderers>

        <mx:series>
            <mx:ColumnSeries id="columnSeries"
                    xField="name"
                    yField="avg"
                    displayName="avg" />
        </mx:series>

        <mx:seriesFilters>
            <mx:Array />
        </mx:seriesFilters>

    </mx:ColumnChart>

</mx:Application>
Attachments
Screen shot 2011-03-21 at 3.01.27 PM.png
Screen shot 2011-03-21 at 3.01.27 PM.png (20.04 KiB) Viewed 749 times
haretu
 
Posts: 132
Joined: Sat Jan 08, 2011 9:56 pm

Return to Adobe FLEX Flash

Who is online

Users browsing this forum: No registered users and 1 guest

cron