SoFunction
Updated on 2025-04-02

Switching sample code through RadioButton in Flex


<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="/mxml/2009"
xmlns:s="library:///flex/spark"
xmlns:mx="library:///flex/mx"
width="100%" height="100%">
<s:layout>
<s:BasicLayout/>
</s:layout>
<fx:Declarations>
<!-- Put non-visual elements (such as services, value objects) here -->
</fx:Declarations>

<fx:Script>
<![CDATA[
import ;

/**
* Figure data source binding
*/
[Bindable]
private var chartArray:ArrayCollection = new ArrayCollection([
{week:"Monday",apple:"451245",orange:"894544",peach:"451245"},
{week:"Tuesday",apple:"985444",orange:"745445",peach:"989565"},
{week:"Wednesday",apple:"124544",orange:"323565",peach:"323121"},
{week:"Thursday",apple:"895645",orange:"201212",peach:"542121"},
{week:"Friday",apple:"325645",orange:"564545",peach:"656454"},
{week:"Saturday",apple:"564512",orange:"784545",peach:"845455"},
{week:"Sunday",apple:"784545",orange:"656232",peach:"124545"}
]);

/**
* RadioButton Click Event
*/
protected function clickHandler(event:Event):void
{
if(radio_column.enabled)
{
= 450;
= 0;
}
else if(radio_line.enabled)
{
= 0;
= 450;
}
}

]]>
</fx:Script>

<mx:VBox width="100%" height="100%">
<mx:VBox width="100%" height="80%" paddingLeft="10" paddingRight="10"
paddingTop="10">
<mx:ColumnChart showDataTips="true" dataProvider="{chartArray}" width="100%" height="450">
<mx:horizontalAxis>
<mx:CategoryAxis categoryField="week" displayName="week"/>
</mx:horizontalAxis>
<mx:series>
<mx:ColumnSeries displayName="Apple" xField="week" yField="apple"/>
<mx:ColumnSeries displayName="Orange" xField="week" yField="orange"/>
<mx:ColumnSeries displayName="peach" xField="week" yField="peach"/>
</mx:series>
</mx:ColumnChart>
<mx:Legend dataProvider="{column}"/>
</mx:VBox>
<mx:VBox width="100%" height="0" paddingLeft="10" paddingRight="10"
paddingTop="10">
<mx:LineChart showDataTips="true" dataProvider="{chartArray}" width="100%" height="100%">
<mx:horizontalAxis>
<mx:CategoryAxis categoryField="week" displayName="week"/>
</mx:horizontalAxis>
<mx:series>
<mx:LineSeries displayName="Apple" xField="week" yField="apple"/>
<mx:LineSeries displayName="Orange" xField="week" yField="orange"/>
<mx:LineSeries displayName="peach" xField="week" yField="peach"/>
</mx:series>
</mx:LineChart>
<mx:Legend dataProvider="{line}"/>
</mx:VBox>
<mx:HBox width="100%" height="30">
<mx:RadioButton name="chart" label="cylindrical chart" click="clickHandler(event)"/>
<mx:RadioButton name="chart" label="line chart" change="clickHandler(event)"/>
</mx:HBox>
</mx:VBox>
</s:Application>