Formatting Legend in Chart in Flex4


 

Formatting Legend in Chart in Flex4

In this section we will discuss the formatting of the Legend in the Chart control.

In this section we will discuss the formatting of the Legend in the Chart control.

Formatting Legend in Chart in Flex4:

In this section we will discuss the formatting of the Legend in the Chart control. You can change the formatting of legend by using CSS and Action script. In this example we will use the CSS property for change the formatting of legend in the chart control.

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:Style>

@namespace s "library://ns.adobe.com/flex/spark";

@namespace mx "library://ns.adobe.com/flex/mx";

mx|Legend{

label-placement:right;

marker-height:30;

marker-width:30;

background-color:#000000;

}

mx|LegendItem{

font-family: verdana;

font-size:12px;

color: #FFFFFF;

font-weight:bold;

}

</fx:Style>

0

<fx:Script>

<![CDATA[

import mx.collections.ArrayCollection;

1

[Bindable]

public var student:ArrayCollection = new ArrayCollection([

{"Stream":"Management", "Girls":1000, "r":10 },

2

{"Stream":"Computer Science", "Girls":800, "r":4 },

{"Stream":"Mechanical", "Girls":200, "r":6 },

{"Stream":"Electical", "Girls":800, "r":3 },

3

{"Stream":"Electronics", "Girls":500, "r":8 },

{"Stream":"Civil", "Girls":300, "r":7 }

]);

4

[Bindable]

public var student1:ArrayCollection = new ArrayCollection([

{"Stream":"Management", "Boys":1400, "r":7},

5

{"Stream":"Computer Science", "Boys":1200, "r":8},

{"Stream":"Mechanical", "Boys":1500, "r":2},

{"Stream":"Electical", "Boys":850, "r":5},

6

{"Stream":"Electronics", "Boys":1000, "r":10},

{"Stream":"Civil", "Boys":900, "r":1}

]);

7

[Bindable]

public var student2:ArrayCollection = new ArrayCollection([

{"Stream":"Management", "TotalStudent":2400, "r":3},

8

{"Stream":"Computer Science", "TotalStudent":2000, "r":7},

{"Stream":"Mechanical", "TotalStudent":1700, "r":4},

{"Stream":"Electical", "TotalStudent":1650, "r":10},

9

{"Stream":"Electronics", "TotalStudent":1500, "r":1},

{"Stream":"Civil", "TotalStudent":1200, "r":9}

]);

0

private function effect():void{

leg1.setStyle("color", "#FFFFFF");

}

1

]]>

</fx:Script>

<s:Panel title="Formatting Legend in Chart Example" width="521" height="520">

2

<s:layout>

<s:VerticalLayout horizontalAlign="center"/>

</s:layout>

3

<mx:BubbleChart id="bubblechart1"

minRadius="1"

maxRadius="10"

4

showDataTips="true"

paddingBottom="10"

paddingLeft="10"

5

paddingRight="10"

paddingTop="10"

width="515">

6

<mx:verticalAxis>

<mx:CategoryAxis categoryField="Stream"

dataProvider="{student}"/>

7

</mx:verticalAxis>

<mx:series>

<mx:BubbleSeries id="as1"

8

xField="Girls"

yField="Stream"

displayName="Girls"

9

fill="{s1}"

stroke="{scs1}"

dataProvider="{student}"

0

radiusField="r"/>

<mx:BubbleSeries id="as2"

xField="Boys"

1

yField="Stream"

displayName="Boys"

fill="{s2}"

2

stroke="{scs2}"

dataProvider="{student1}"

radiusField="r"/>

3

<mx:BubbleSeries id="as3"

xField="TotalStudent"

yField="Stream"

4

displayName="TotalStudent"

fill="{s3}"

stroke="{scs3}"

5

dataProvider="{student2}"

radiusField="r"/>

</mx:series>

6

</mx:BubbleChart>

<s:Panel height="74" title="Legend">

<mx:Legend id="leg1"

7

dataProvider="{bubblechart1}"

direction="horizontal"

height="41" cornerRadius="20"/>

8

</s:Panel>

</s:Panel>

</s:Application>

9

Output:

Running Application:

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

Download this code

Ads