Quick Themeable Bargraphs with PHP

If you're wanting to do anything at all more than what you see in the below demo I suggest you wander over and take a look at jpGraph. But if all you need is quick and dirty....

The Demo


This PHP snippet, originally written by Steve Maranda, is because I wanted to change the colors of the output graphs without creating another copy of the generater script. This is just Steve's original code modified it enough to add very modest theme support.

The package contains 2 files. The first is the main bar graph file, the other an array of colors. Both are required to use this, and both need to be in the same directory (unless you modify the REQUIRE() of course).

Steve's original Query String layout also remains intact. I have only added the extra theme=.

To create bar graphs, you can simply call the script in your browser, or use the IMG tag in your HTML page.

/bargraph.php?title=Test Graph&width=400&data=Test1^20^^Test2^25^^Test3^12^^Test4^15^^

<IMG SRC="/bargraph.php?title=Test Graph&width=400&data=Test1^20^^Test2^25^^Test3^12^^Test4^15^^" >

The Theme definition is only required if you want to use a theme other than the default, which is the colors of Steve's original script. You can try the sample themes that I have include as demonstrated below:

/bargraph.php?title=Test Graph&width=400&theme=green&data=Test1^20^^Test2^25^^Test3^12^^Test4^15^^

<IMG SRC="/bargraph.php?title=Test Graph&width=400&theme=green&data=Test1^20^^Test2^25^^Test3^12^^Test4^15^^" >

The theme definition data is in an array. To add your own theme copy the theme titled "template" and paste it in right below. Then simply change the name and color definitions and go!

The tgz file is here.

You can also view the bargraphing and colors array.