本文和大家重点讨论一下多样化Flex饼图样式,主要包括颜色渐变,点击分离和环形等,相信通过本文的介绍你对Flex饼图的样式一定会有新的认识。
Flex多样化饼图样式
创建一个简单的环形Flex饼图,通过PieChart的innerRadius属性进行设置实现环形效果:
Xml代码
- <?xmlversionxmlversion="1.0"encoding="utf-8"?>
- <mx:Applicationxmlns:mxmx:Applicationxmlns:mx="http://www.adobe.com/2006/mxml"layout="absolute">
- <mx:Script>
- <![CDATA[
- importmx.collections.ArrayCollection;
- importmx.charts.HitData;
- [Bindable]
- publicvarchengjiPie:ArrayCollection=newArrayCollection([
- {classs:"60分以下",num:5},
- {classs:"60~70分",num:4},
- {classs:"70~80分",num:5},
- {classs:"80~90分",num:4},
- {classs:"90分以上",num:3}]);
- privatefunctiondisplayGold(data:Object,field:String,index:Number,percentValue:Number):String{
- vartemp:String=(""+percentValue).substr(0,6);
- returndata.classs+":"+'\n'+temp+"%";
- }
- ]]>
- </mx:Script>
- <mx:SolidColoridmx:SolidColorid="sc1"color="0xE46899"alpha=".6"/>
- <mx:SolidColoridmx:SolidColorid="sc2"color="0xAAD71A"alpha=".6"/>
- <mx:SolidColoridmx:SolidColorid="sc3"color="0xFFE30E"alpha=".6"/>
- <mx:SolidColoridmx:SolidColorid="sc4"color="0xFDB500"alpha=".6"/>
- <mx:SolidColoridmx:SolidColorid="sc5"color="0x4CD0EF"alpha=".6"/>
- <mx:Strokeidmx:Strokeid="callouts"weight="2"color="0x999999"alpha=".8"caps="square"/>
- <mx:Strokeidmx:Strokeid="radial"weight="1"color="0xFFFFCC"alpha=".3"/>
- <mx:Strokeidmx:Strokeid="pieborder"color="0x000000"weight="2"alpha=".5"/>
- <mx:Panelheightmx:Panelheight="100%"width="100%"layout="absolute"fontSize="12">
- <mx:PieChartidmx:PieChartid="chart"showDataTips="true"width="100%"height="100%"
- dataProvider="{chengjiPie}"innerRadius=".3"horizontalCenter="0"verticalCenter="0">
- <mx:series>
- <mx:Array>
- <mx:PieSeriesnameFieldmx:PieSeriesnameField="classs"labelPosition="callout"field="num"
- labelFunction="displayGold">
- </mx:PieSeries>
- </mx:Array>
- </mx:series>
- </mx:PieChart>
- <mx:LegenddataProvidermx:LegenddataProvider="{chart}"right="0"bottom="0"/>
- </mx:Panel>
- </mx:Application>
- <?xmlversionxmlversion="1.0"encoding="utf-8"?>
- <mx:Applicationxmlns:mxmx:Applicationxmlns:mx="http://www.adobe.com/2006/mxml"layout="absolute">
- <mx:Script>
- <![CDATA[
- importmx.collections.ArrayCollection;
- importmx.charts.HitData;
- [Bindable]
- publicvarchengjiPie:ArrayCollection=newArrayCollection([
- {classs:"60分以下",num:5},
- {classs:"60~70分",num:4},
- {classs:"70~80分",num:5},
- {classs:"80~90分",num:4},
- {classs:"90分以上",num:3}]);
- privatefunctiondisplayGold(data:Object,field:String,index:Number,percentValue:Number):String{
- vartemp:String=(""+percentValue).substr(0,6);
- returndata.classs+":"+'\n'+temp+"%";
- }
- ]]>
- </mx:Script>
- <mx:SolidColoridmx:SolidColorid="sc1"color="0xE46899"alpha=".6"/>
- <mx:SolidColoridmx:SolidColorid="sc2"color="0xAAD71A"alpha=".6"/>
- <mx:SolidColoridmx:SolidColorid="sc3"color="0xFFE30E"alpha=".6"/>
- <mx:SolidColoridmx:SolidColorid="sc4"color="0xFDB500"alpha=".6"/>
- <mx:SolidColoridmx:SolidColorid="sc5"color="0x4CD0EF"alpha=".6"/>
- <mx:Strokeidmx:Strokeid="callouts"weight="2"color="0x999999"alpha=".8"caps="square"/>
- <mx:Strokeidmx:Strokeid="radial"weight="1"color="0xFFFFCC"alpha=".3"/>
- <mx:Strokeidmx:Strokeid="pieborder"color="0x000000"weight="2"alpha=".5"/>
- <mx:Panelheightmx:Panelheight="100%"width="100%"layout="absolute"fontSize="12">
- <mx:PieChartidmx:PieChartid="chart"showDataTips="true"width="100%"height="100%"
- dataProvider="{chengjiPie}"innerRadius=".3"horizontalCenter="0"verticalCenter="0">
- <mx:series>
- <mx:Array>
- <mx:PieSeriesnameFieldmx:PieSeriesnameField="classs"labelPosition="callout"field="num"
- labelFunction="displayGold">
- </mx:PieSeries>
- </mx:Array>
- </mx:series>
- </mx:PieChart>
- <mx:LegenddataProvidermx:LegenddataProvider="{chart}"right="0"bottom="0"/>
- </mx:Panel>
- </mx:Application>
◆在这个简单Flex饼图的基础上进行一些改动就可以实现多样化:
1添加Flex饼图上颜色块的渐变效果,用到RadialGradient标签.
2实现鼠标点击,该块分离的效果,对PieSeries进行相关属性设置,explodeRadius:分离程度。PerWedgeExplodeRadius:数组规定出每一块的分离值。
3添加动态效果,点击时的弹动变化。showDataEffect标签处添加Elastic.easeOut震动效果。
【编辑推荐】