Main Content

Drawing dynamic graphs in PHP

Archive - Originally posted on "The Horse's Mouth" - 2007-03-09 19:27:12 - Graham Ellis

The web is all about presenting data, and a picture paints a thousand words - so what's better than a graph to quickly and easily present figures and trend to yor web site visitor?

There's a great deal of software available to produce static diagrams and graphs as image files - .gif or .jpg are the most common formats - and there's a lot of professional / marketing sites which that use them. But what if you want your diagrams to change as the data held on your server changes?

In PHP, the Gd package allows you to generate images on the fly - and it works very well. But those are images ("graphics") based on the pixel addressing of the image and you've still got a lot of conversion, clipping and presentation to do if you want a graph of (say) ticket sales from 2000 to 2007 along the X axis, with a vertical scale from 0 to 50,000 on Y ... when the image is 600 x 450.

That's where additional graphic packages such as Phplot come in to play ... you can specify just the data sets, a few key parameters, and the titles and the work is done for you.

There's a PHPlot example on our website, and you'll find links from that page to the PHPlot download.