This little hack of a script generates a histogram image (PNG format) for data sets given as CGI parameters.
Download
Get the script here : histogram.py. Rename it to histogram.cgi.
Install and configure
To install, put the script somewhere in your web server's file space, and enable the web server to execute the new installation as a CGI script. You'll need to have Python (version 2.1 or later) and the Python Imaging Library installed.
If you really trust this software, then you might just want to install it in your web server's /cgi-bin/ directory, which is probably already configured for CGI script execution. Before you do this, however, note that this script is distributed under the terms of the GNU GPL and hence comes with NO WARRANTY.
If you install the script somewhere else, you'll likely need to do some additional configuration. With Apache, for example, if you installed the script in a web directory called /scripts/python, then you'll need to add some lines to your server's httpd.conf file as follows :
<Location /scripts/python>
AddHandler cgi-script .cgi
Options ExecCGI
</Location>
The descriptions in the next section assume the script is located at the URL http://foo.net/bar/histogram.cgi.
Use
This script will generate a histogram containing all multiple-value data types passed as parameters. For example, to generate a histogram with values of 1, 2, 3, and 1, call the script like this :
http://foo.net/bar/histogram.cgi?q=1&q=2&q=3&q=1
This URL will produce an image like this :
And to draw a histogram with another data set, just append the points for second data set, using a different name for the second data set :
http://foo.net/bar/histogram.cgi?q=1&q=2&q=3&q=1&e=1.1&e=1.5&e=3&e=2.3
This URL will produce an image like this :
You can display up to 100 data sets on one histogram, though that is easily extensible (just extend the length of the series_colors list in the script).
The names of the data sets are ignored. At some remote point in the future there could conceivably be support for automatically drawing a legend, and then the data set names will be taken into account. Don't count on it, though !
A couple of final notes :
All data sets will be zero-padded to the length of the longest given data set.
If any data points contain non-numeric data, they will produce an error and the histogram will not be drawn.
All data sets must have at least two data points, otherwise they will be ignored.
No tic marks, numbers, or text of any kind is drawn on the histograms. They are intended mostly for qualitative data analysis.
I haven't tested this thing with negative data sets yet, although it should work in theory.
Parameters
The most essential script parameters, as indicated above, are the ones you make up : just assign a label to each data set, and pass each data point in the data set as a parameter with the data set's label.
There are some other parameters available to customize the output a bit.
height – The height of the image, in pixels.
width – The width of the image, in pixels.
space – The space between sets of bars, in pixels.
type – For histograms with more than one data set, gives the type of bars to draw.
There are currently three bar types available :
overlap – The default, creates histograms with slightly overlapping bars at each data point.
stack – Creates histograms with stacked bars at each data point (often useful for percentage charts, and always guaranteed to draw the widest possible bars).
anything else – Draws bars for multiple data sets side-by-side at each data point (which results in the narrowest bars).
Also note that there aren't parameters available for configuring the colors of the data sets. Too bad, I'm just tired at this point, and I like the default colors. :-) I hope you can get some use out of this script regardless.
Contact
Leif Johnson : <leif@ambient.2y.net>

