Share on Google+Share on Google+

BarChart control in Flex4

Advertisement
The BarChart Control is a MX Component. There is no Spark component.

BarChart control in Flex4:

The BarChart Control is a MX Component. There is no Spark component.
The BarChart Control represents the data in horizontal bars whose length determined the value of the data. You can provide the data to the chart control  by using data provider property. You will use <mx:horizontalAxis> or <mx:verticalAxis> and <mx:Series> in it. You will use xField, yField and displayName property for series. You can use more than one series in it. It's essentially like a ColumnChart rotate 90 degree clockwise. The tag of BarChart Control is <mx:BarChart>.

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

<fx:Declarations>

<s:SolidColor id="s1" color="#990000" alpha=".5"/>

<s:SolidColor id="s2" color="#808080" alpha=".5"/>

<s:SolidColor id="s3" color="#cc00cc" alpha=".5"/>

<s:SolidColorStroke id="scs1" color="#990000" weight="2"/>

<s:SolidColorStroke id="scs2" color="#808080" weight="2"/>

<s:SolidColorStroke id="scs3" color="#cc00cc" weight="2"/>

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

]);

]]>

</fx:Script>

<s:Panel title="BarChart control Example" width="617">

<s:layout>

<s:HorizontalLayout/>

</s:layout>

<mx:BarChart id="barchart1"

showDataTips="true"

paddingBottom="10"

paddingLeft="10"

paddingRight="10"

paddingTop="10"

dataProvider="{student}"

width="515">

<mx:verticalAxis>

<mx:CategoryAxis categoryField="Stream"

dataProvider="{student}"/>

</mx:verticalAxis>

<mx:series>

<mx:BarSeries id="as1"

xField="Girls"

yField="Stream"

displayName="Girls"

fill="{s1}"

stroke="{scs1}"/>

<mx:BarSeries id="as2"

xField="Boys"

yField="Stream"

displayName="Boys"

fill="{s2}"

stroke="{scs2}"/>

<mx:BarSeries id="as3"

xField="TotalStudent"

yField="Stream"

displayName="TotalStudent"

fill="{s3}"

stroke="{scs3}"/>

</mx:series>

</mx:BarChart>

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

</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 4, 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.