Use Single-choice buttons in flex to switch the horizontal and vertical coordinates and descriptions of a bar chart

Source: Internet
Author: User

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
  1. <? XML version = "1.0" encoding = "UTF-8"?>
  2. <S: Application xmlns: FX = "http://ns.adobe.com/mxml/2009"
  3. Xmlns: S = "Library: // ns.adobe.com/flex/spark"
  4. Xmlns: MX = "Library: // ns.adobe.com/flex/mx"
  5. Width = "100%" Height = "100%"
  6. Creationcomplete = "inithandler (event )"
  7. Fontfamily = "" fontsize = "12">
  8. <S: layout>
  9. <S: basiclayout/>
  10. </S: layout>
  11. <FX: SCRIPT>
  12. <! [CDATA [
  13. Import MX. Collections. arraycollection;
  14. Import MX. Controls. Alert;
  15. Import MX. Events. flexevent;
  16. Import MX. Events. itemclickevent;
  17. [Bindable]
  18. // Graph data binding
  19. Private var chartarray: arraycollection = new arraycollection ([
  20. {Week: "Monday", month: "January", person: "8989", rate: "56 "},
  21. {Week: "Tuesday", month: "February", person: "5675", rate: "43 "},
  22. {Week: "Wednesday", month: "March", person: "7234", rate: "12 "},
  23. {Week: "Thursday", month: "April", person: "3456", rate: "76 "},
  24. {Week: "Friday", month: "May", person: "6355", rate: "49 "},
  25. {Week: "Saturday", month: "June", person: "4356", rate: "32 "},
  26. {Week: "Sunday", month: "July", person: "9087", rate: "87 "}
  27. ]);
  28. /**
  29. * Initialization Function
  30. */
  31. Protected function inithandler (Event: flexevent): void
  32. {
  33. }
  34. /**
  35. * Query button Functions
  36. */
  37. Protected function search_clickhandler (Event: mouseevent): void
  38. {
  39. }
  40. /**
  41. * Single-choice button switching function
  42. */
  43. Protected function radiogroup_itemclickhandler (Event: itemclickevent): void
  44. {
  45. If (event. currenttarget. selectedvalue = "Week ")
  46. {
  47. Datax. categoryfield = "Week ";
  48. Datax. displayname = "Week ";
  49. Date. xfield = "Week ";
  50. Date. yfield = "person ";
  51. Date. displayname = "Number of Students ";
  52. }
  53. Else if (event. currenttarget. selectedvalue = "month ")
  54. {
  55. Datax. categoryfield = "month ";
  56. Datax. displayname = "month ";
  57. Date. xfield = "month ";
  58. Date. yfield = "rate ";
  59. Date. displayname = "ratio ";
  60. }
  61. }
  62. ]>
  63. </FX: SCRIPT>
  64. <FX: declarations>
  65. <S: radiobuttongroup id = "radiogroup" itemclick = "radiogroup_itemclickhandler (event)"/>
  66. </FX: declarations>
  67. <S: vgroup width = "100%" Height = "100%" paddingbottom = "10" paddingleft = "10" paddingright = "20"
  68. Paddingtop = "10" horizontalalign = "center">
  69. <S: hgroup width = "100%" Height = "30" paddingleft = "10" verticalalign = "Middle">
  70. <S: Label text = "date type:"/>
  71. <S: Label width = "20"/>
  72. <S: radiobutton label = "Week" groupname = "radiogroup" value = "Week" selected = "true"/>
  73. <S: Label width = "20"/>
  74. <S: radiobutton label = "month" groupname = "radiogroup" value = "month"/>
  75. <S: Label width = "60"/>
  76. <S: button label = "query" id = "Search" Click = "search_clickhandler (event)"/>
  77. </S: hgroup>
  78. <Mx: columnchart id = "column" dataprovider = "{chartarray}" width = "100%" Height = "80%" columnwidthratio = "0.4"
  79. Showdatatips = "true">
  80. <Mx: horizontalaxis>
  81. <Mx: categoryaxis id = "datax" categoryfield = "Week" displayname = "Week"/>
  82. </MX: horizontalaxis>
  83. <Mx: Series>
  84. <Mx: columnseries displayname = "" id = "date" xfield = "Week" yfield = "person"/>
  85. </MX: Series>
  86. </MX: columnchart>
  87. <Mx: Legend dataprovider = "{column}"/>
  88. </S: vgroup>
  89. </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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.