Adobe
Products

Top destinations

  • Adobe Creative Cloud
  • Creative Suite
  • Adobe Marketing Cloud
  • Acrobat
  • Photoshop
  • SiteCatalyst
  • Students
  • Elements family

Adobe Creative Cloud

  • What is Adobe Creative Cloud?
  • Design
  • Web
  • Photography
  • Video
  • Students
  • Teams
  • Enterprise
  • Educational institutions

Design and photography

  • Photoshop
  • Illustrator
  • InDesign
  • Adobe Muse
  • Lightroom

Video

  • Adobe Premiere
  • After Effects

Web development and HTML5

  • Edge Tools & Services [opens in a new window]
  • Dreamweaver
  • Gaming [opens in a new window]

Adobe Marketing Cloud

  • What is Adobe Marketing Cloud?
  • Digital analytics
  • Social marketing
  • Web experience management
  • Testing and targeting
  • Media optimization

Analytics

  • SiteCatalyst
  • Adobe Discover
  • Insight

Social

  • Adobe Social

Experience Manager

  • CQ
  • Scene7

Target

  • Test&Target
  • Recommendations
  • Search&Promote

Media Optimizer

  • AdLens
  • AudienceManager
  • AudienceResearch

Document services

  • Acrobat
  • EchoSign [opens in a new window]
  • FormsCentral [opens in a new window]
  • SendNow [opens in a new window]
  • Acrobat.com [opens in a new window]

Publishing

  • Digital Publishing Suite

  • See all products
Business solutions

By business need

  • Digital analytics
  • Digital publishing
  • Document management
  • Media optimization
  • Social marketing
  • Testing and targeting
  • Video editing and serving
  • Web development [opens in a new window]
  • Web experience management
  • See all business needs

By industry

  • Broadcast
  • Education
  • Financial services
  • Government
  • Publishing
  • Retail
  • See all industries
Support & Learning

I need help

  • Products
  • Adobe Creative Cloud
  • Adobe Marketing Cloud
  • Forums [opens in a new window]

I want to learn

  • Training and tutorials
  • Certification [opens in a new window]
  • Adobe Developer Connection
  • Adobe Design Center
  • Adobe TV [opens in a new window]
  • Adobe Marketing Center
  • Adobe Labs [opens in a new window]
Download
  • Product trials
  • Adobe Flash Player
  • Adobe Reader
  • Adobe AIR
  • See all downloads
Company
  • Careers at Adobe
  • Investor Relations
  • Newsroom
  • Privacy
  • Corporate Social Responsibility
  • Customer Showcase
  • Contact us
  • More company info
Buy
  • For personal and professional use
  • For students, educators, and staff
  • For small and medium businesses
  • Volume Licensing
  • Special offers
  • Adobe Marketing Cloud sales [opens in a new window]
Search
 
Info Sign in
Why sign in? Sign in to manage your account and access trial downloads, product extensions, community areas, and more.
Welcome,
My Adobe
My orders
My information
My preferences
My products and services
Sign out
My cart
Privacy My Adobe
Adobe
Products Sections Buy   Search  
Solutions Company
Help Learning
Sign in Sign out Privacy My Adobe
Preorder Estimated Availability Date. Your credit card will not be charged until the product is shipped. Estimated availability date is subject to change. Preorder Estimated Availability Date. Your credit card will not be charged until the product is ready to download. Estimated availability date is subject to change.
Qty:
Purchase requires verification of academic eligibility
Subtotal
Promotions
Estimated shipping
Tax
Calculated at checkout
Total
Review and Checkout
Adobe Developer Connection / Flex Developer Center / Flex Test Drive /

Flex Test Drive: Add charts and graphs

by Adobe

Adobe logo

Modified

27 June 2011

Page tools

Share on Facebook
Share on Twitter
Share on LinkedIn
Bookmark
Print
Flash BuilderFlexRIA
Was this helpful?
Yes   No

By clicking Submit, you accept the Adobe Terms of Use.

 
Thanks for your feedback.

Video | Code | Tutorial | Links

Format charts

 

This content requires Flash To view this content, JavaScript must be enabled, and you need the latest version of the Adobe Flash Player. To view this content, JavaScript must be enabled, and you need the latest version of the Adobe Flash Player.

Download the Test Drive solution files (ZIP, 14 MB)

Code

FlexWebTestDrive.css

@namespace s "library://ns.adobe.com/flex/spark"; (...) mx|PieSeries{ fills:#6B96D0,#5B7FB2,#81A4D0,#7EC2EA,#6B84A5,#686BD0,#6A8AD0; } .grayFill{ fill:#999999; } mx|ColumnChart { axisTitleStyleName:boldTitles; } .boldTitles{ fontWeight:bold; }

FlexWebTestDrive.mxml

<s:Application ...> <fx:Script> <![CDATA[ (...) import mx.charts.HitData; import mx.charts.chartClasses.IAxis; import mx.charts.series.items.PieSeriesItem; protected function deptPieCht_itemClickHandler(event:ChartItemEvent):void { currentState="DepartmentDetails"; deptColCht.dataProvider=createDataProvider(event.hitData.item); expenseAxis.title=event.hitData.item.name+" Expenses"; estSeries.setStyle("fill",(event.hitData.chartItem as PieSeriesItem).fill); } protected function axisMoneyFormatter(labelValue:Object, previousValue:Object, axis:IAxis):String{ return moneyFormatter.format(labelValue); } protected function formatDeptPieTips(hitData:HitData):String{ return "<b>" + hitData.item.name + "</b><br/>"+"Budget: " + moneyFormatter.format(hitData.item.budget); } ]]> </fx:Script> <fx:Declarations> (...) <s:SolidColorStroke id="dkgrayStrokeThick" color="#4D4D4D" weight="5"/> <s:SolidColorStroke id="dkgrayStrokeThin" color="#4D4D4D" weight="1"/> <s:CurrencyFormatter id="moneyFormatter" useCurrencySymbol="true" currencySymbol="$" fractionalDigits="0"/> </fx:Declarations> (...) <mx:PieChart id="deptPieCht" showDataTips="true" itemClick="deptPieCht_itemClickHandler(event)" dataTipFunction="formatDeptPieTips" .../> (...) <mx:ColumnChart id="deptColCht" includeIn="DepartmentDetails" x="337" y="254" width="363" height="278" showDataTips="true"> <mx:series> <mx:ColumnSeries id="estSeries" displayName="Estimated" yField="est" showDataEffect="{interpolate}"/> <mx:ColumnSeries displayName="Actual" yField="actual" showDataEffect="{interpolate}" styleName="grayFill"/> </mx:series> <mx:horizontalAxis> <mx:CategoryAxis id="expenseAxis" title="Expenses" categoryField="field"/> </mx:horizontalAxis> <mx:verticalAxis> <mx:LinearAxis id="amountAxis" title="Amount" minimum="0" maximum="500000" labelFunction="axisMoneyFormatter"/> </mx:verticalAxis> <mx:verticalAxisRenderers> <mx:AxisRenderer verticalAxisTitleAlignment="vertical" axis="{amountAxis}" axisStroke="{dkgrayStrokeThick}" tickStroke="{dkgrayStrokeThin}"/> </mx:verticalAxisRenderers> <mx:horizontalAxisRenderers> <mx:AxisRenderer axis="{expenseAxis}" axisStroke="{dkgrayStrokeThick}" tickStroke="{dkgrayStrokeThin}"/> </mx:horizontalAxisRenderers> </mx:ColumnChart> <mx:Legend .../> </s:Application>

Tutorial

In this tutorial, you customize the pie and column charts. You change fill, axis, and tick colors; rotate axis titles; format axis titles and labels; and format data tips.

Step 1: Set chart fill colors.

In FlexWebTestDrive.css, create a PieSeries type selector with the fills style set to a list of at least seven colors (#6B96D0, #5B7FB2,#81A4D0, #7EC2EA, #6B84A5, #686BD0, #6A8AD0). Create a class selector called grayFill with fill set to some color (#5B7FB2). In FlexWebTestDrive.mxml, set the styleName property of the Actual ColumnSeries to grayFill.

Your new selectors should appear as shown here:

mx|PieSeries{ fills:#6B96D0,#5B7FB2,#81A4D0,#7EC2EA,#6B84A5,#686BD0,#6A8AD0; } .grayFill{ fill:#5B7FB2; }

Your ColumnSeries should appear as shown here:

<mx:ColumnSeries displayName="Actual" yField="actual" styleName="grayFill" .../>

Run the application and drill down into department data. You should see your new colors in the pie and column charts (see Figure 1). You will set the color of the first column series to match the color of the selected item in the pie chart next.

Customize the chart fill colors.
Figure 1. Customize the chart fill colors.

Step 2: Set a column fill color dynamically.

Assign the first ColumnSeries an id of estSeries and in the deptPieCht itemClick handler, use setStyle() to set the fill style to the color of the selected pie chart item: (event.hitData.chartItem as PieSeriesItem).fill.

Your ColumnSeries should appear as shown here:

<mx:ColumnSeries id="estSeries" displayName="Estimated" yField="est" showDataEffect="{interpolate}"/>

Your handler should appear as shown here:

protected function deptPieCht_itemClickHandler(event:ChartItemEvent):void { currentState="DepartmentDetails"; deptColCht.dataProvider=createDataProvider(event.hitData.item); expenseAxis.title=event.hitData.item.name+" Expenses"; estSeries.setStyle("fill",(event.hitData.chartItem as PieSeriesItem).fill); }

Be sure to select PieSeriesItem from Code Assist so the appropriate import statement is written for you:

import mx.charts.series.items.PieSeriesItem;

Run the application. When you select a department in the pie chart, the first series in the column chart is now the same color (see Figure 2). Look at the position of the vertical axis title; you will flip this in the next step.

 Match the colors of the selected pie chart item and the first column series.
Figure 2. Match the colors of the selected pie chart item and the first column series.

Step 3: Rotate the axis title.

Set the LinearAxis id to amountAxis and set the ColumnChart verticalAxisRenderers property to an instance of the AxisRenderer class. For the AxisRenderer, set the verticalAxisTitleAlignment style to vertical and the axis property to amountAxis.

Your code should appear as shown here:

<mx:verticalAxis> <mx:LinearAxis id="amountAxis" title="Amount" minimum="0" maximum="500000"/> </mx:verticalAxis> <mx:verticalAxisRenderers> <mx:AxisRenderer verticalAxisTitleAlignment="vertical" axis="{amountAxis}"/> </mx:verticalAxisRenderers>

Run the application. The vertical axis title should now be rotated (see Figure 3).

Rotate the vertical axis title.
Figure 3. Rotate the vertical axis title.

Step 4: Make the axis titles bold.

In FlexWebTestDrive.css, create a ColumnChart type selector and set axisTitleStyleName to a class selector called boldTitles. Create the class selector called boldTitles and set its fontWeight to bold.

Your selectors should appear as shown here:

mx|ColumnChart { axisTitleStyleName:boldTitles; } .boldTitles{ fontWeight:bold; }

Run the application. The axis titles should now be bold (see Figure 4).

Make the axis titles bold.
Figure 4. Make the axis titles bold.

Step 5: Set axis and tick colors.

In the Declarations block, create a SolidColorStroke object called dkgrayStrokeThick and set its color (#4D4D4D) and its weight (5). Create a second SolidColorStroke object called dkGrayStrokeThin and set its color (#4D4D4D) and its weight (1). In the ColumnChart verticalAxisRenderer, set axisStroke and tickStroke to the dkgrayStrokeThick and dkgrayStrokeThin objects. Set the horizontalAxisRenderers property to an instance of the AxisRenderer class and set its axis to expenseAxis and its stroke styles the same as the other renderer.

Your declarations should appear as shown here:

<s:SolidColorStroke id="dkgrayStrokeThick" color="#4D4D4D" weight="5"/> <s:SolidColorStroke id="dkgrayStrokeThin" color="#4D4D4D" weight="1"/>

Your axis renderers should appear as shown here:

<mx:verticalAxisRenderers> <mx:AxisRenderer verticalAxisTitleAlignment="vertical" axis="{amountAxis}" axisStroke="{dkgrayStrokeThick}" tickStroke="{dkgrayStrokeThin}"/> </mx:verticalAxisRenderers> <mx:horizontalAxisRenderers> <mx:AxisRenderer axis="{expenseAxis}" axisStroke="{dkgrayStrokeThick}" tickStroke="{dkgrayStrokeThin}"/> </mx:horizontalAxisRenderers>

Run the application. The axes and ticks should now be dark gray (see Figure 5).

Change the axis and tick colors.
Figure 5. Change the axis and tick colors.

Step 6: Format axis labels as currencies.

In the Declarations block, create a Spark CurrencyFormatter called moneyFormatter and set its properties to format in your currency. In the LinearAxis tag, set its labelFunction to axisMoneyFormatter. In the Script block, include the formatter function shown below.

Here is an example of currency displayed in US dollars with no decimal places:

<s:CurrencyFormatter id="moneyFormatter" useCurrencySymbol="true" currencySymbol="$" fractionalDigits="0"/>

Your LinearAxis should appear as shown here:

<mx:LinearAxis id="amountAxis" title="Amount" minimum="0" maximum="500000" labelFunction="axisMoneyFormatter"/>

Here is the formatter function to place in your Script block:

import mx.charts.chartClasses.IAxis; protected function axisMoneyFormatter(labelValue:Object, previousValue:Object, axis:IAxis):String{ return moneyFormatter.format(labelValue); }

This function is called by the chart component for every label on the vertical axis. Its method signature (its arguments and return type) are defined by the component using it. You can look up the method's required signature in the API for the LinearAxis class.

Run the application. The vertical axis labels should now be formatted as currencies (see Figure 6).

Format the vertical axis labels as currencies.
Figure 6. Format the vertical axis labels as currencies.

Step 7: Format data tips.

Set the PieChart dataTipFunction to formatDeptPieTips. In the Script block, include the formatter function shown below.

Your PieChart opening tag should appear as shown here:

<mx:PieChart id="deptPieCht" includeIn="DepartmentChart,DepartmentDetails" x="50" y="250" width="282" height="282" dataProvider="{deptDg.dataProvider}" showDataTips="true" itemClick="deptPieCht_itemClickHandler(event)" dataTipFunction="formatDeptPieTips">

Here is the formatter function to place in your Script block:

import mx.charts.HitData; protected function formatDeptPieTips(hitData:HitData):String{ return "<b>"+hitData.item.name+"</b><br/>"+"Budget: " +moneyFormatter.format(hitData.item.budget); }

This function is called by the chart component before displaying every data tip. Just as for the labelFunction in the last step, its method signature is defined by the component using it, the PieChart, and you can look it up in the API for the PieChart class. Notice you can use basic HTML formatting in this function.

Run the application. The pie chart data tips should now be formatted to display currency amounts (see Figure 7).

 Format data tips.
Figure 7. Format data tips.

In this module you learned to add charts to your Flex application. You used a pie chart and a column chart and accomplished all the common customization tasks including drilling down into data; animating data changes; and formatting fills, axes, titles, labels, and data tips. 

This concludes your Test Drive of Flash Builder 4.5. In less than a day, you learned to build a Flex application that retrieves, displays, updates, adds, and deletes data in a database and you learned to debug, deploy, customize, and add charts to this application (see Figure 8). To build on your knowledge, continue on to the Flex in a Week training.

 Browse the finished application.
Figure 8. Browse the finished application.

Learn more

Documentation: Using Flex 4.5

  • Formatting charts
  • Displaying data and labels in charts
  • Using data tip objects
  • Spark formatters

ActionScript 3 Reference

  • mx.charts
  • mx.charts.effects
  • spark.formatters

Creative Commons Attribution-Noncommercial-Share Alike 3.0 Unported License+Adobe Commercial Rights

This work is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 3.0 Unported License. Permissions beyond the scope of this license, pertaining to the examples of code included within this work are available at Adobe.

More Like This

  • Flex Test Drive: Modify the database
  • Flex Test Drive: Build an application in an hour
  • Flex Test Drive: Change the appearance of your application
  • Flex Test Drive: Build an application in an hour
  • Flex Test Drive: Deploy your application to a web server
  • Flex Test Drive: Add charts and graphs
  • Test Drive: Deploy your application to a web server
  • Flex Test Drive: Build an application in an hour
  • Flex Test Drive: Build an application in an hour
  • Flex Test Drive: Modify the database

Tutorials and samples

Tutorials

  • Flex mobile performance checklist
  • Flex and Maven with Flexmojos – Part 3: Journeyman
  • Migrating Flex 3 applications to Flex 4.5 – Part 4

Samples

  • Twitter Trends
  • Flex 4.5 reference applications
  • Mobile Trader Flex app on Android Market

Flex user forum

More
05/15/2013 XSS Cross Site Scripting Issue in Flex messagebroker amfsecure URLs
05/21/2013 Can we make an accordian in which change not work on click
12/17/2012 need secure video streaming in Flex mobile for iOS
01/24/2008 AdvancedDataGrid Drag Drop Error

Flex Cookbook

More

Products

  • Adobe Creative Cloud
  • Creative Suite
  • Adobe Marketing Cloud
  • Acrobat
  • Photoshop
  • Digital Publishing Suite
  • Elements family
  • SiteCatalyst
  • For education

Download

  • Product trials
  • Adobe Reader
  • Adobe Flash Player
  • Adobe AIR

Support & Learning

  • Product help
  • Forums

Buy

  • For personal and professional use
  • For students, educators, and staff
  • For small and medium businesses
  • Volume Licensing
  • Special offers

Company

  • News room
  • Partner programs
  • Corporate social responsibility
  • Career opportunities
  • Investor Relations
  • Events
  • Legal
  • Security
  • Contact Adobe
Choose your region United States (Change)
Choose your region Close

North America

Europe, Middle East and Africa

Asia Pacific

  • Canada - English
  • Canada - Français
  • Latinoamérica
  • México
  • United States

South America

  • Brasil
  • Africa - English
  • Österreich - Deutsch
  • Belgium - English
  • Belgique - Français
  • België - Nederlands
  • България
  • Hrvatska
  • Česká republika
  • Danmark
  • Eastern Europe - English
  • Eesti
  • Suomi
  • France
  • Deutschland
  • Magyarország
  • Ireland
  • Israel - English
  • ישראל - עברית
  • Italia
  • Latvija
  • Lietuva
  • Luxembourg - Deutsch
  • Luxembourg - English
  • Luxembourg - Français
  • الشرق الأوسط وشمال أفريقيا - اللغة العربية
  • Middle East and North Africa - English
  • Moyen-Orient et Afrique du Nord - Français
  • Nederland
  • Norge
  • Polska
  • Portugal
  • România
  • Россия
  • Srbija
  • Slovensko
  • Slovenija
  • España
  • Sverige
  • Schweiz - Deutsch
  • Suisse - Français
  • Svizzera - Italiano
  • Türkiye
  • Україна
  • United Kingdom
  • Australia
  • 中国
  • 中國香港特別行政區
  • Hong Kong S.A.R. of China
  • India - English
  • 日本
  • 한국
  • New Zealand
  • 台灣

Southeast Asia

  • Includes Indonesia, Malaysia, Philippines, Singapore, Thailand, and Vietnam - English

Copyright © 2013 Adobe Systems Incorporated. All rights reserved.

Terms of Use | Privacy | Cookies

Ad Choices

Reviewed by TRUSTe: site privacy statement