Share on Google+Share on Google+

PieChart Control in Flex4

Advertisement
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,

 index:Number, percentValue:Number):String {

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

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

}

private function clickHandler():void{

ps.explodeRadius=.05;

}

]]>

</fx:Script>

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

<s:layout>

<s:VerticalLayout/>

</s:layout>

<mx:PieChart id="pieChart"

dataProvider="{chartData}"

showDataTips="true"

width="564" height="412"

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

<mx:series>

<mx:PieSeries id="ps"

field="litres"

nameField="country"

displayName="country"

labelPosition="callout"

labelFunction="displaylitres"

filters="[]"

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

</mx:series>

</mx:PieChart>

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

</s:Panel>

</s:Application>

Output:

Running Application:

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

Download this code

Advertisements

Posted on: June 9, 2010 If you enjoyed this post then why not add us on Google+? Add us to your Circles

Share this Tutorial Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.