Make Simple Graph

PHP July 12th, 2008

Today, I tried to make simple graph with PHP. I read it on PHP Hack book By Jack Herrington and I’ll share it for you. It seems as though every site you go to these days requires QuickTime or Flash so that you can see fancy images and graphs. With this tricks you don’t need fancy image rendering or Flash movies. So it doesn’t require any extra plug-ins or downloads. Nice^^

Preview from browser:

Simple Graph

You can use several techniques to create HTML graphs. I chose to use two tables; the first contains the textual data, and the second contains a set of nested tables, each with a width value based on the graph value in that row.

I calculate the width by first finding the maximum value of the combined data, and storing that in $max. I then derive the percentage by dividing $max by the current value, and multiplying the result by 100 (to set the scale between 0 and 100). That number is stored in $percent, which is then used in the width attribute of the table.

Adding color:

Preview from browser:
Simple Graph Color

Sphere: Related Content

Tags: , ,
1 Star2 Stars3 Stars4 Stars5 Stars (No Ratings Yet)
Loading ... Loading ...






Related Post:


Leave a Comment

Blogroll Link Update