Share on Google+Share on Google+

Chart Effect in Flex4

Advertisement
Chart uses the standard Flex effect like Zoom and Fade.

Chart Effect in Flex4:

Chart uses the standard Flex effect like Zoom and Fade. There are some standard effect for chart series which is: SeriesInterpolate, SeriesSlide, SeriesZoom. These classes uses the mx.charts.effects.effects package. The base class for chart effect is SeriesEffect. You can triggered the effect on focusInEffect, focusOutEffect, moveEffect, showEffect, and hideEffect. In this example we use a two dropdownlist: Category field and Choose Chart effect. First you will select form Category field and after that Chart effect and you will see the effect of series.

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" initialize="init()">

<fx:Declarations>

<s:SolidColor id="s1" color="#738994"/>

<mx:SeriesInterpolate id="seriesInterpolate" duration="800"/>

<mx:SeriesSlide id="seriesSlide" duration="800" direction="up"/>

<mx:SeriesZoom id="seriesZoom"

duration="1000"

minimumElementDuration="50"

elementOffset="50"

verticalFocus="top"

horizontalFocus="left"

relativeTo="chart"/>

</fx:Declarations>

<fx:Script>

<![CDATA[

import mx.collections.ArrayCollection;

[Bindable]

public var student:ArrayCollection = new ArrayCollection([

{Stream: "Management", Girls:1000, Boys:1400, TotalStudent:2400},

{Stream: "Computer Science", Girls:800, Boys:1200, TotalStudent:2000},

{Stream: "Mechanical", Girls:200, Boys:1500, TotalStudent:1700},

{Stream: "Electical", Girls:800, Boys:850, TotalStudent:1650},

{Stream: "Electronics", Girls:500, Boys:1000, TotalStudent:1500},

{Stream: "Civil", Girls:300, Boys:900, TotalStudent:1200}

]);

private function update():void {

var str:String = catfDP.selectedItem.data;

if(str == "Girls"){

cs1.yField = str;

cs1.displayName = str;

cs1.setStyle("fill" , "738994");

}else if(str == "Boys"){

cs1.yField = str;

cs1.displayName = str;

cs1.setStyle("fill" , "999990");

}else{

cs1.yField = str;

cs1.displayName = str;

cs1.setStyle("fill" , "406374");

}

}

private function init():void{

catfDP.selectedIndex= 0;

effectDP.selectedIndex= 0;

}

]]>

</fx:Script>

<s:Panel title="Chart Effect Example" width="627" height="565">

<s:layout>

<s:VerticalLayout/>

</s:layout>

<mx:ApplicationControlBar dock="true" width="625" height="82">

<mx:Form>

<mx:FormItem label="Category Field:">

<s:DropDownList id="catfDP" change="update();" prompt="--Select--" width="136"

 height="19">

<s:dataProvider>

<mx:ArrayList>

<fx:Object data="Girls" label="Girls" />

<fx:Object data="Boys" label="Boys" />

<fx:Object data="TotalStudent" label="TotalStudent" />

</mx:ArrayList>

</s:dataProvider>

</s:DropDownList>

</mx:FormItem>

<mx:FormItem label="Choose Chart Effect:">

<s:DropDownList id="effectDP" change="update();" width="136" prompt="--Select--">

<s:dataProvider>

<mx:ArrayList>

<fx:Object label="seriesInterpolate" data="{seriesInterpolate}" />

<fx:Object label="seriesSlide" data="{seriesSlide}" />

<fx:Object label="seriesZoom" data="{seriesZoom}" />

</mx:ArrayList>

</s:dataProvider>

</s:DropDownList>

</mx:FormItem>

</mx:Form>

</mx:ApplicationControlBar>

<mx:ColumnChart id="cchart"

dataProvider="{student}"

showDataTips="true"

width="621"

fontFamily="verdana" height="402">

<mx:verticalAxis>

<mx:LinearAxis title="Number of Students" />

</mx:verticalAxis>

<mx:horizontalAxis>

<mx:CategoryAxis dataProvider="{student}"

categoryField="Stream"

title="Stream"/>

</mx:horizontalAxis>

<mx:series>

<mx:ColumnSeries id="cs1"

xField="Stream"

yField="Girls"

displayName="Girls"

fill="{s1}"

showDataEffect="{effectDP.selectedItem.data}"/>

</mx:series>

</mx:ColumnChart>

<s:HGroup>

<mx:Legend dataProvider="{cchart}"

direction="horizontal"/>

<s:VGroup>

</s:VGroup>

</s:HGroup>

</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

Advertisement

Posted on: June 12, 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.