Home Tutorial Flex Flex4 Components Chart Item Event in Flex4

 
 

Share on Google+Share on Google+
Chart Item Event in Flex4
Posted on: June 12, 2010 at 12:00 AM
Advertisement
Chart uses the ChartItemEvent when you perform the operation click on the chart Item. This event is the part of chart package.

Chart Item Event in Flex4:

Chart uses the ChartItemEvent when you perform the operation click on the chart Item. This event is the part of chart package. ChartItemEvent is used by the mx.charts.events package. If your mouse sensitivity is greater than 3 then the ChartItemEvent will not work. In this example you will show the value of item when you click on the data item. If you click on the chart the result will display data not found.

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

<fx:Declarations>

<s:SolidColor id="s1" color="#870606" alpha=".9"/>

<mx:SeriesSlide

id="slideIn"

duration="1000"

direction="up"/>

</fx:Declarations>

<fx:Script>

<![CDATA[

import mx.collections.ArrayCollection;

import mx.charts.events.ChartEvent;

import mx.charts.events.ChartItemEvent;

// Chart Event

private function chartEventHandler(event:ChartEvent):void {

txt.text= "NO";

txt1.text= "Data Not Found";

txt2.text= "Data Not Found";

}

// Chart Item Event

public function listener(e:ChartItemEvent):void {

txt.text= "Yes";

txt1.text = "Girls in"+ " " + e.hitData.item.Stream+ " " + "branch are ="+ " " +

e.hitData.item.Girls;

txt2.text = "X:" +e.hitData.x + "\n"+ "Y:" + e.hitData.y;

}

public function init():void {

cchart.addEventListener(ChartItemEvent.ITEM_CLICK, listener);

}

// Data using Array Collection

[Bindable]

public var student:ArrayCollection = new ArrayCollection([

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

{Stream: "Computer Science", Girls:900, Boys:1200, TotalStudent:2100},

{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}

]);

]]>

</fx:Script>

<s:Panel title="Chart Item Event Example" width="627" height="569">

<s:layout>

<s:VerticalLayout/>

</s:layout>

<mx:ColumnChart id="cchart"

dataProvider="{student}"

showDataTips="true"

width="621"

fontFamily="verdana" chartClick="chartEventHandler(event);" height="369">

<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="slideIn"/>

</mx:series>

</mx:ColumnChart>

<s:HGroup>

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

<s:VGroup>

<mx:Form backgroundColor="#000000"

cornerRadius="30"

fontFamily="verdana"

width="493"

color="#FFFFFF"

fontWeight="bold" height="146">

<mx:FormItem label="Data Found:">

<mx:TextInput id="txt"

height="30" width="301"

color="#000000"/>

</mx:FormItem>

<mx:FormItem label="Student:">

<mx:TextInput id="txt1"

height="30" width="301"

color="#000000"/>

</mx:FormItem>

<mx:FormItem label="X and Y Coordinate:">

<mx:TextInput id="txt2"

height="42" width="301"

color="#000000"/>

</mx:FormItem>

</mx:Form>

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

Advertisement

Related Tags for Chart Item Event in Flex4:


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.

Posted on: June 12, 2010

Recommend the tutorial

Advertisements Advertisements
 

 

 

DMCA.com