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

Creating donut charts


Very similar to pie charts, donut charts allow you to vary the visual if you have been using pie charts a lot. And since we used Flex to build the pie chart in the previous recipe, we thought it would be good to show how to build a pie chart/donut chart using pure ActionScript 3.

Getting ready

This recipe bases some of its code on the wedge class by Adobe's evangelist Lee Brimelow; you can check it here: http://www.leebrimelow.com/?p=430. Apart from that you can look up the code you will get from http://www.packtpub.com.

How to do it...

The following are the steps required to build a donut chart:

  1. We will start by creating the data class in this case DonutChartData.as.

    public var color : uint;
    public var percent : Number;
    public function DonutChartData(newPercent:Number, newColor:uint){
      percent = newPercent;
      color = newColor;
    
    }
  2. From there we will create the visual building block of this chart: DonutChartWedge.as. This class could also be used in a pie chart. The following...