Flex4中使用组件添加柱状图、饼状图等图表

1.添加一个最简单的柱状图

<?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" minWidth="955" minHeight="600">
	<s:layout>
		<s:BasicLayout/>
	</s:layout>
	<fx:Declarations>
		<!-- 将非可视元素(例如服务、值对象)放在此处 -->
	</fx:Declarations>
	<fx:Script>
		<![CDATA[
			[Bindable]
			private var arr:Array = [{id:1,city:'北京',money:1000,pay:300},{id:2,city:'上海',money:1200,pay:500},{id:3,city:'天津',money:800,pay:200}];
			
		]]>
	</fx:Script>
	<mx:BarChart x="110" y="27" id="barchart1" dataProvider="{arr}" showDataTips="true" selectionMode="single">
		<mx:series>
			<mx:BarSeries displayName="收入" xField="money" />
			<mx:BarSeries displayName="支出" xField="pay" />
		</mx:series>
		<mx:verticalAxis>
			<mx:CategoryAxis categoryField="city" />
		</mx:verticalAxis>
	</mx:BarChart>
	<mx:Legend dataProvider="{barchart1}"/>
</s:Application>

 

这个例子使用Array做为数据源,柱状图使用mx:BarChart组件,这个例子很简单,就不讲解了

 

2.在上面例子的基础上,添加一个特效,就是图表默认是半透明的,在鼠标移到图标上时渐变为不透明,移开时渐变为半透明

<?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" minWidth="955" minHeight="600">
	<s:layout>
		<s:BasicLayout/>
	</s:layout>
	<fx:Declarations>
		<!-- 将非可视元素(例如服务、值对象)放在此处 -->
	</fx:Declarations>
	<fx:Script>
		<![CDATA[
			[Bindable]
			private var arr:Array = [{id:1,city:'北京',money:1000,pay:300},{id:2,city:'上海',money:1200,pay:500},{id:3,city:'天津',money:800,pay:200}];
			
		]]>
	</fx:Script>
	<mx:BarChart alpha="0.5" x="110" y="27" id="barchart1" dataProvider="{arr}" showDataTips="true" selectionMode="single">
		<mx:series>
			<mx:BarSeries displayName="收入" xField="money" />
			<mx:BarSeries displayName="支出" xField="pay" />
		</mx:series>
		<mx:verticalAxis>
			<mx:CategoryAxis categoryField="city" />
		</mx:verticalAxis>
		<mx:rollOverEffect>
			<s:Fade alphaFrom="0.5" alphaTo="1" duration="1000" />
		</mx:rollOverEffect>
		<mx:rollOutEffect>
			<s:Fade alphaFrom="1" alphaTo="0.5" duration="1000" />
		</mx:rollOutEffect>
	</mx:BarChart>
	<mx:Legend dataProvider="{barchart1}"/>
</s:Application>

 

 

3.添加一个最简单的饼状图

<?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" minWidth="955" minHeight="600">
	<s:layout>
		<s:BasicLayout/>
	</s:layout>
	<fx:Script>
		<![CDATA[
			[Bindable]
			private var arr:Array = [{id:1,city:'北京',money:1000,pay:300},{id:2,city:'上海',money:1200,pay:500},{id:3,city:'天津',money:800,pay:200}];
			
		]]>
	</fx:Script>	
	<fx:Declarations>
		<!-- 将非可视元素(例如服务、值对象)放在此处 -->
	</fx:Declarations>
	<mx:PieChart x="110" y="51" id="piechart1" dataProvider="{arr}" showAllDataTips="true" selectionMode="single">
		<mx:series>
			<mx:PieSeries displayName="Series 1" field="money" labelPosition="callout" labelField="city" nameField="city" />
		</mx:series>
	</mx:PieChart>
	<mx:Legend dataProvider="{piechart1}" direction="horizontal" labelPlacement="right"  />
</s:Application>

 

这里需要说明一下mx:PieSeries标签里面的几个属性:labelField和labelPosition分别是指饼图每块显示的内容和位置,nameField是指图例Legend显示的内容

 

4.添加一个竖版柱状图

<?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" minWidth="955" minHeight="600">
	<s:layout>
		<s:BasicLayout/>
	</s:layout>
	<fx:Script>
		<![CDATA[
			[Bindable]
			private var arr:Array = [{id:1,city:'北京',money:1000,pay:300},{id:2,city:'上海',money:1200,pay:500},{id:3,city:'天津',money:800,pay:200}];
			
		]]>
	</fx:Script>
	<fx:Declarations>
		<!-- 将非可视元素(例如服务、值对象)放在此处 -->
	</fx:Declarations>
	<mx:ColumnChart x="100" y="90" id="columnchart1" dataProvider="{arr}" showDataTips="true" selectionMode="single">
		<mx:horizontalAxis>
			<mx:CategoryAxis categoryField="city" />
		</mx:horizontalAxis>
		<mx:series>
			<mx:ColumnSeries displayName="收入" yField="money"/>
			<mx:ColumnSeries displayName="支出" yField="pay"/>
		</mx:series>
	</mx:ColumnChart>
	<mx:Legend dataProvider="{columnchart1}"/>
</s:Application>

跟第一个例子非常相似,只是使用的组件是mx:ColumnChart

转载于:https://www.cnblogs.com/modou/articles/1896668.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值