[prog] On the fly graphs with php

Conor Daly conor.daly-linuxchix at cod.homelinux.org
Fri Jul 15 18:23:46 EST 2005


On Fri, Jul 15, 2005 at 05:28:28PM +1000 or so it is rumoured hereabouts, 
Jacinta Richardson thought:
> 
> Conor Daly wrote:
> 
> > I'm trying to generate a line graph from a dataset returned by a database
> > query in php.  I've looked at various web resources and they all seem to
> > propose:
> > 
> > <img src="chart.php"/>
> > 
> > as the way to generate a chart where chart.php is a script of my own
> > devising which properly scales the chart, normalises the data and draws
> > everything.  Now, that would be fine if I could figure out how to call
> > functions within chart.php .  For example, I want to call the function
> > makeImage($height, $width, $numPoints, $xAxisLabels, $points1, $points2...)
> 
> I think you may be making this harder for yourself than you need to be.
> Rather than passing the dataset from your query to chart.php why can't you pass
> the parameters used to generate that dataset and get chart.php to access the
> database and do the hard work all in one place?

Two reasons why not.  

1.  The upstream program that calls chart.php is one that allows the user
    to:
	o See what tables are in the DB.
	o See what numeric (int, float, decimal, money (though we don't
	  have any)) columns exist in the table.
	o Select up to four columns to plot.
	o Choose the selection criteria (station number and date 'cos
	  that's how all of our weather obs data is stored).
	o Plot the data.
    This program attempts to be an 'intelligent' creator of sql queries.

2.  I want chart.php to be available for other purposes so that other
    users can easily add a line chart to their script/page without
    necessarily going near the DB.

I see various charting classes out there which I could probably use but
all of these seem to need their data coded somewhere in a script that gets
called as an <img...> tag.  This is also something of a learning exercise
for me...

Conor
-- 
Conor Daly <conor.daly at oceanfree.net>

Domestic Sysadmin :-)
---------------------
Hobbiton.cod.ie
 09:15:00  up 8 days, 12:09,  1 user,  load average: 0.03, 0.01, 0.00


More information about the Programming mailing list