Book Image

ActionScript Graphing Cookbook

Book Image

ActionScript Graphing Cookbook

Overview of this book

"A picture is worth a thousand words" has never been more true than when representing large sets of data. Bar charts, heat maps, cartograms, and many more have become important tools in applications and presentations to quickly give insight into complicated issues.The "ActionScript Graphing Cookbook" shows you how to add your own charts to any ActionScript program. The recipes give step-by-step instructions on how to process the input data, how to create various types of charts and how to make them interactive for even more user engagement.Starting with basic ActionScript knowledge, you will learn how to develop many different types of charts.First learn how to import your data, from Excel, web services and more. Next process the data and make it ready for graphical display. Pick one of the many graph options available as the book guides you through ActionScript's drawing functions. And when you're ready for it, branch out into 3D display.The recipes in the "ActionScript Graphing Cookbook" will gradually introduce you into the world of visualization.
Table of Contents (17 chapters)
ActionScript Graphing Cookbook
Credits
About the Authors
About the Reviewers
www.PacktPub.com
Preface
Index

Preface

The cookbook that you are reading will show you how to draw a myriad of graphs in ActionScript. ActionScript is one of the easiest ways to represent graphical information to users across browsers and platforms. It allows you to add a wide range of dynamic effects and interactions to your graphs and charts.

We'll start from the humble beginnings, explaining a little about the ActionScript display list and end at full-blown interactive 3D graphs. In between, you will get to see what goes into animating graphs, adding interaction, and much, much more.

What this book covers

Chapter 1, Getting Started with Graph Drawing, goes over the basics of drawing in ActionScript. We cover everything needed to draw graphs, such as the display list and transformations.

Chapter 2, Working with Data, will explain how you can import data into your ActionScript program. There are many types of graphs, but all of them are based on data.

Chapter 3, Creating Bar Charts, gives us all the tools to create multiple bar charts. Be it vertical, horizontal, comparison, or histograms, this chapter will provide solid bases to improve those charts even more.

Chapter 4, Drawing Different Types of Graphs, will go through an array of different charts, each presented in different recipes, some common such as the Venn diagram, some less common such as the Treemap.

Chapter 5, Adding Interaction, covers how you can give the user various options to interact with the graph. Selecting, zooming, and panning will be explained as well as a few other options.

Chapter 6, Mapping Geographical and Spatial Data, will show how to bring data and maps together to derive further meaning. We will start with simple recipes just showing a map and points of interest and ending up generating heat maps.

Chapter 7, Animating a Graph, explores how to animate graphs using different techniques and animation libraries.

Chapter 8, Creating a Relational Network, shows how to create a relational network, a data visualization that is used to represent a tree data structure, from scratch.

Chapter 9, Creating Three-Dimensional Graphs, lays the groundwork for drawing 3D graphs. Although this is not for the faint of heart, 3D graphs can add a tremendous "wow" factor to your application. This is the first chapter on 3D that gives a high-level overview of everything involved in drawing in 3D, and shows how you can draw some basic graphs.

Chapter 10, Working with Various 3D Graph Types, goes all out on 3D. We'll show you why 3D can add real value to your graphs by applying data to models of real life objects.

What you need for this book

In order to compile and run the examples in this book, you need an ActionScript compiler, which was most likely included with the ActionScript IDE that you are using. You can also use the freely available Flex SDK (http://www.adobe.com/devnet/flex/flex-sdk-download.html).

You can create the ActionScript files in any text editor you want, but the example code uses FlashDevelop (http://www.flashdevelop.org/). The code will also work verbatim with any other Flash editor, but you may need to use slightly different menu options than the ones mentioned in the How to do it... sections. However, the differences will be minimal.

Most of the book's code can run with any ActionScript 3 player, but the 3D chapters require at least version 11. You may also want to install the debug version of the players, because these add some useful features for development. They can be downloaded from http://www.adobe.com/support/flashplayer/downloads.html.

Who this book is for

This book is for anyone interested in creating interactive and dynamic graphs in ActionScript. Some programming knowledge is required to understand the examples, preferably in ActionScript 3, but you will be able to understand most of the code if you know any modern object-oriented programming language (for example, Java or C#).

Although an understanding of the ActionScript 3 display list will be very useful, it is not a requirement. The parts needed for drawing graphs are all explained in the first chapter and throughout the book whenever something new is introduced.

Conventions

In this book, you will find a number of styles of text that distinguish between different kinds of information. Here are some examples of these styles, and an explanation of their meaning.

Code words in text are shown as follows: "The _keyData object and the addKey method use coordinates and sizes that were obtained in a drawing program (such as Adobe Photoshop)."

A block of code is set as follows:

private function addKey(x:Number, z:Number, usage:Number):Mesh
    {
      var keyGeometry:CubeGeometry = new CubeGeometry(54,usage,54);
      var key:Mesh = new Mesh(keyGeometry, _material);

      key.x = -1 * (x + 27 - 512);
      key.y = usage / 2 + 3;
      key.z = z + 27 - 256;

      addChild(key);

      return key;
    }

New terms and important words are shown in bold. Words that you see on the screen, in menus or dialog boxes for example, appear in the text like this: "In FlashDevelop, right-click on greensock.swc and choose Add To Library."

Note

Warnings or important notes appear in a box like this.

Tip

Tips and tricks appear like this.

Reader feedback

Feedback from our readers is always welcome. Let us know what you think about this book—what you liked or may have disliked. Reader feedback is important for us to develop titles that you really get the most out of.

To send us general feedback, simply send an e-mail to , and mention the book title through the subject of your message.

If there is a topic that you have expertise in and you are interested in either writing or contributing to a book, see our author guide on www.packtpub.com/authors.

Customer support

Now that you are the proud owner of a Packt book, we have a number of things to help you to get the most from your purchase.

Downloading the example code

You can download the example code files for all Packt books you have purchased from your account at http://www.packtpub.com. If you purchased this book elsewhere, you can visit http://www.packtpub.com/support and register to have the files e-mailed directly to you.

Downloading the color images of this book

We also provide you a PDF fle that has color images of the screenshots/diagrams used in this book. The color images will help you beter understand the changes in the output. You can download this file from http://www.packtpub.com/sites/default/files/downloads/3202_Images.pdf.

Errata

Although we have taken every care to ensure the accuracy of our content, mistakes do happen. If you find a mistake in one of our books—maybe a mistake in the text or the code—we would be grateful if you would report this to us. By doing so, you can save other readers from frustration and help us improve subsequent versions of this book. If you find any errata, please report them by visiting http://www.packtpub.com/support, selecting your book, clicking on the errata submission form link, and entering the details of your errata. Once your errata are verified, your submission will be accepted and the errata will be uploaded to our website, or added to any list of existing errata, under the Errata section of that title.

Piracy

Piracy of copyright material on the Internet is an ongoing problem across all media. At Packt, we take the protection of our copyright and licenses very seriously. If you come across any illegal copies of our works, in any form, on the Internet, please provide us with the location address or website name immediately so that we can pursue a remedy.

Please contact us at with a link to the suspected pirated material.

We appreciate your help in protecting our authors, and our ability to bring you valuable content.

Questions

You can contact us at if you are having a problem with any aspect of the book, and we will do our best to address it.