1. Problem Description
A group of single-choice buttons can be divided into weeks and months. Select "Week". The horizontal coordinate of the bar chart shows the Week, and the vertical coordinate shows the number of people. Select "month" and the horizontal coordinate of the column chart shows the month, the ordinate value shows the ratio.
2. Demo instance
[Plain]View plaincopy
- <? XML version = "1.0" encoding = "UTF-8"?>
- <S: Application xmlns: FX = "http://ns.adobe.com/mxml/2009"
- Xmlns: S = "Library: // ns.adobe.com/flex/spark"
- Xmlns: MX = "Library: // ns.adobe.com/flex/mx"
- Width = "100%" Height = "100%"
- Creationcomplete = "inithandler (event )"
- Fontfamily = "" fontsize = "12">
- <S: layout>
- <S: basiclayout/>
- </S: layout>
- <FX: SCRIPT>
- <! [CDATA [
- Import MX. Collections. arraycollection;
- Import MX. Controls. Alert;
- Import MX. Events. flexevent;
- Import MX. Events. itemclickevent;
- [Bindable]
- // Graph data binding
- Private var chartarray: arraycollection = new arraycollection ([
- {Week: "Monday", month: "January", person: "8989", rate: "56 "},
- {Week: "Tuesday", month: "February", person: "5675", rate: "43 "},
- {Week: "Wednesday", month: "March", person: "7234", rate: "12 "},
- {Week: "Thursday", month: "April", person: "3456", rate: "76 "},
- {Week: "Friday", month: "May", person: "6355", rate: "49 "},
- {Week: "Saturday", month: "June", person: "4356", rate: "32 "},
- {Week: "Sunday", month: "July", person: "9087", rate: "87 "}
- ]);
- /**
- * Initialization Function
- */
- Protected function inithandler (Event: flexevent): void
- {
- }
- /**
- * Query button Functions
- */
- Protected function search_clickhandler (Event: mouseevent): void
- {
- }
- /**
- * Single-choice button switching function
- */
- Protected function radiogroup_itemclickhandler (Event: itemclickevent): void
- {
- If (event. currenttarget. selectedvalue = "Week ")
- {
- Datax. categoryfield = "Week ";
- Datax. displayname = "Week ";
- Date. xfield = "Week ";
- Date. yfield = "person ";
- Date. displayname = "Number of Students ";
- }
- Else if (event. currenttarget. selectedvalue = "month ")
- {
- Datax. categoryfield = "month ";
- Datax. displayname = "month ";
- Date. xfield = "month ";
- Date. yfield = "rate ";
- Date. displayname = "ratio ";
- }
- }
- ]>
- </FX: SCRIPT>
- <FX: declarations>
- <S: radiobuttongroup id = "radiogroup" itemclick = "radiogroup_itemclickhandler (event)"/>
- </FX: declarations>
- <S: vgroup width = "100%" Height = "100%" paddingbottom = "10" paddingleft = "10" paddingright = "20"
- Paddingtop = "10" horizontalalign = "center">
- <S: hgroup width = "100%" Height = "30" paddingleft = "10" verticalalign = "Middle">
- <S: Label text = "date type:"/>
- <S: Label width = "20"/>
- <S: radiobutton label = "Week" groupname = "radiogroup" value = "Week" selected = "true"/>
- <S: Label width = "20"/>
- <S: radiobutton label = "month" groupname = "radiogroup" value = "month"/>
- <S: Label width = "60"/>
- <S: button label = "query" id = "Search" Click = "search_clickhandler (event)"/>
- </S: hgroup>
- <Mx: columnchart id = "column" dataprovider = "{chartarray}" width = "100%" Height = "80%" columnwidthratio = "0.4"
- Showdatatips = "true">
- <Mx: horizontalaxis>
- <Mx: categoryaxis id = "datax" categoryfield = "Week" displayname = "Week"/>
- </MX: horizontalaxis>
- <Mx: Series>
- <Mx: columnseries displayname = "" id = "date" xfield = "Week" yfield = "person"/>
- </MX: Series>
- </MX: columnchart>
- <Mx: Legend dataprovider = "{column}"/>
- </S: vgroup>
- </S: Application>
3. instance result
(1) During Initialization
(2) Select "month"
Use Single-choice buttons in flex to switch the horizontal and vertical coordinates and descriptions of a bar chart