• actionscript
  • as3
  • flash
  • programming

Graph Classes written in ActionScript 3

Whilst doing some work on a Mathematics Learning Object I was confronted with the problem of displaying a variety of different graphs.

Due to the way that these projects change over the construction period it soon became apparent that hand drawing these graphs would be too time consuming, so I set out to create some classes that could do most of the heavy lifting.

After a bit of planning and a lot of head scratching I finally came up with some classes that would do 95% of what I needed to do with the added bonus of being run from an external XML file structure.

I did have a flash project that showed off what it could do, but flash doesn’t work anymore, so here is a picture of what it looked like:

Graph Preview

Without getting into the boring details it basically works like this:

  • One class handles the grid. It draws grid lines based on the area being viewed and the physical size of the graph.
  • A second class, the Graph class, manages all of the graph elements. It acts as a parent to them all, telling them when the graph dimensions or co-ordinates change etc.
  • A base class for all of the different ‘graph items’ acts as a common interface for all the different types of graphing elements you want to display. Each element knows how to render itself based on current graph settings.

That’s about it. There was lots of little nuances like conditionals controlling line visibility and figuring out what numbers should appear, etc. but nothing that was hard.

Download

I’ve added a downloadable version of the demo shown above because a lot of people have been asking me for it. I would like to add though that this was written a long time ago and I would do it all totally different now. Enjoy.

Download Graph AS3 source files