Graphing with PHP

In this and next weeks’ tutorials we will be building on what we have covered by developing a set of basic objects that you can use for drawing graphs from dynamic data. After all, what use is having these great tools for drawing graphs and charts if you can't draw them dynamically? If that were the case you may as well stick to using Macromedia Fireworks or exporting a graph from Microsoft Excel.
 
We'll build up a PHP script that implements a graph object. We’ll start simple and explain the whys and wherefores as we go along – don’t worry of you missed the previous two articles as we'll do some quick revision as we go along.

Today we:
  1. create  a script that implements a class to store all of our graph data. 
  2. We will instantiate the object in our main script and give it all the information about our graph. 
  3. Once we have all of the data in place we will then write out our image tag. 
  4. As that happens we will save the entire object into a session variable and pass an identifier to that session variable to the graph drawing script.
  5. The graph drawing script will then access the graph data object through the session variable and draw the graph accordingly.

This tutorial contains some maths, but the code is provided and is suitable for intermediate PHP developers using either Dreamweaver MX or MX 2004.

$2.79
- OR -

Overview

Table of Content:

  • So where to begin
  • Building a framework
  • gaph_dataclass.php
  • graph_viewer.php
  • graph.php
  • Adding to the data class
  • A new graph_viewer.php

Allan Kent

Allan KentAllan comes from Cape Town, South Africa. He has been implicated in writing for several WROX, glasshaus, Wiley and Apress publications, generally in the 'cool stuff that PHP can do' sections.

You can catch up with him at his website http://www.mediafrenzy.co.za.

See All Postings From Allan Kent >>

Reviews

Be the first to write a review

You must me logged in to write a review.