<?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">
<fx:Script>
<![CDATA[
import mx.collections.ArrayCollection;
[Bindable]
private var db:ArrayCollection = new ArrayCollection ([
{country:"美国",gold:35,sliver:20,bronze:10},
{country:"中国",gold:60,sliver:25,bronze:10},
{country:"日本",gold:2,sliver:10,bronze:8}
]);
private function showMoreInfo(data:Object, field:String, index:Number, percentValue:Number):String{
//data表示传进来的整个对象,你可以访问他的各种属性了.field表示目前你用了哪个属性(这里是gold).
//index是顺序(也就是美国0,中国1,日本2),percentValue是百分比(他的返回值很长,比如36.0815241424);
var percent:String = percentValue.toString().substr(0,6);
return data.country + "\n 金牌总数:" + data.gold + "\n 银牌总数:" + data.sliver + "\n 百分比:" + percent + "%";
}
]]>
</fx:Script>
<fx:Declarations>
<!-- 将非可视元素(例如服务、值对象)放在此处 -->
</fx:Declarations>
<mx:PieChart id="pie" dataProvider="{db}" width="50%" height="50%" showDataTips="true">
<mx:series>
<mx:PieSeries field="gold" labelPosition="callout" nameField="country" labelFunction="showMoreInfo">
<!-- 清除掉投影-->
<mx:filters> <fx:Array/></mx:filters>
<!-- 内部分割线条 -->
<mx:radialStroke>
<mx:SolidColorStroke weight="1" color="#ffffff" alpha="0.3" />
</mx:radialStroke>
<!-- 圆周边 边线 -->
<mx:stroke>
<mx:SolidColorStroke weight="2" color="#000000" alpha="0.5" />
</mx:stroke>
<!-- 提示信息的线 -->
<mx:calloutStroke>
<mx:SolidColorStroke weight="1" color="#000000" alpha="0.5" />
</mx:calloutStroke>
</mx:PieSeries>
</mx:series>
</mx:PieChart>
<!-- 图例说明 -->
<mx:Legend dataProvider="{pie}" />
</s:Application>
<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">
<fx:Script>
<![CDATA[
import mx.collections.ArrayCollection;
[Bindable]
private var db:ArrayCollection = new ArrayCollection ([
{country:"美国",gold:35,sliver:20,bronze:10},
{country:"中国",gold:60,sliver:25,bronze:10},
{country:"日本",gold:2,sliver:10,bronze:8}
]);
private function showMoreInfo(data:Object, field:String, index:Number, percentValue:Number):String{
//data表示传进来的整个对象,你可以访问他的各种属性了.field表示目前你用了哪个属性(这里是gold).
//index是顺序(也就是美国0,中国1,日本2),percentValue是百分比(他的返回值很长,比如36.0815241424);
var percent:String = percentValue.toString().substr(0,6);
return data.country + "\n 金牌总数:" + data.gold + "\n 银牌总数:" + data.sliver + "\n 百分比:" + percent + "%";
}
]]>
</fx:Script>
<fx:Declarations>
<!-- 将非可视元素(例如服务、值对象)放在此处 -->
</fx:Declarations>
<mx:PieChart id="pie" dataProvider="{db}" width="50%" height="50%" showDataTips="true">
<mx:series>
<mx:PieSeries field="gold" labelPosition="callout" nameField="country" labelFunction="showMoreInfo">
<!-- 清除掉投影-->
<mx:filters> <fx:Array/></mx:filters>
<!-- 内部分割线条 -->
<mx:radialStroke>
<mx:SolidColorStroke weight="1" color="#ffffff" alpha="0.3" />
</mx:radialStroke>
<!-- 圆周边 边线 -->
<mx:stroke>
<mx:SolidColorStroke weight="2" color="#000000" alpha="0.5" />
</mx:stroke>
<!-- 提示信息的线 -->
<mx:calloutStroke>
<mx:SolidColorStroke weight="1" color="#000000" alpha="0.5" />
</mx:calloutStroke>
</mx:PieSeries>
</mx:series>
</mx:PieChart>
<!-- 图例说明 -->
<mx:Legend dataProvider="{pie}" />
</s:Application>