PieChart Control in Flex4


 

PieChart Control in Flex4

The PieChart Control is a MX Component. There is no Spark component.

The PieChart Control is a MX Component. There is no Spark component.

PieChart control in Flex4:

The PieChart Control is a MX Component. There is no Spark component. The PieChart Control is a circular chart in which the wedges represent to the data value. You can provide the data to the chart control by using data provider property. You will use the PieSeries Class for creating a pie series. You will use Field, labelPosition, nameField property for Pieseries. You can set the label position by using labelposition property. You can provide the space between each wedges by using explodeRadius property. You can set the color by using <mx:SolidColor>. The tag of PieChart Control is <mx:PieChart>.

Example:

<?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" height="734">

<fx:Declarations>

<mx:SolidColor id="sc1" color="blue" alpha=".5"/>

<mx:SolidColor id="sc2" color="red" alpha=".5"/>

<mx:SolidColor id="sc3" color="green" alpha=".5"/>

<mx:SolidColor id="sc4" color="gray" alpha=".5"/>

<mx:SolidColor id="sc5" color="black" alpha=".5"/>

<mx:SolidColor id="sc6" color="yellow" alpha=".5"/>

<mx:SolidColor id="sc7" color="purple" alpha=".5"/>

<mx:SolidColor id="sc8" color="silver" alpha=".5"/>

</fx:Declarations>

<fx:Script>

<![CDATA[

import mx.collections.ArrayCollection;

[Bindable]

private var chartData:ArrayCollection = new ArrayCollection( [

{country:"Czech Republic",litres:156.90},

{country:"India",litres:200.90},

{country:"Ireland",litres:131.10},

{country:"Germany",litres:115.80},

{country:"Australia",litres:109.90},

{country:"Austria",litres:125.30},

{country:"UK",litres:99.00},

{country:"Belgium",litres:40.00}]);

private function displaylitres(data:Object, field:String,

0

 index:Number, percentValue:Number):String {

var temp:String= (" " + percentValue).substr(0,6);

return data.country + ": " + '\n' + "Litres: " + data.litres + '\n' + temp + "%";

1

}

private function clickHandler():void{

ps.explodeRadius=.05;

2

}

]]>

</fx:Script>

3

<s:Panel title="PieChart Control Example" width="574" height="667">

<s:layout>

<s:VerticalLayout/>

4

</s:layout>

<mx:PieChart id="pieChart"

dataProvider="{chartData}"

5

showDataTips="true"

width="564" height="412"

innerRadius=".3" click="clickHandler()">

6

<mx:series>

<mx:PieSeries id="ps"

field="litres"

7

nameField="country"

displayName="country"

labelPosition="callout"

8

labelFunction="displaylitres"

filters="[]"

fills="{[sc1, sc2, sc3, sc4, sc5, sc6, sc7, sc8]}"/>

9

</mx:series>

</mx:PieChart>

<mx:Legend dataProvider="{pieChart}"/>

0

</s:Panel>

</s:Application>

Output:

1

Running Application:

To view this page ensure that Adobe Flash Player version 10.0.0 or greater is installed.

Download this code

2

Ads