Creating a Line graph.

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Simon Angell
Forum Commoner
Posts: 45
Joined: Fri Jan 24, 2003 12:14 am

Creating a Line graph.

Post by Simon Angell »

Hi.
I am looking to make a line graph using data from an outside file.
In this case its called Temp.log

In Temp.log the data is written like
9.1,2350
9.0,0000
8.6,0010
8.5,0020
8.2,0030
etc etc

With the first being the Temperature, and the second (after the comma) being the time.
How can i get php to get open that file, parse the data and output the relevent Line graph?
User avatar
CoderGoblin
DevNet Resident
Posts: 1425
Joined: Tue Mar 16, 2004 10:03 am
Location: Aachen, Germany

Post by CoderGoblin »

OK cannot go into too much depth as don't have time so to give you some pointers....

http://de3.php.net/manual/en/ref.filesystem.php
and
http://de3.php.net/manual/en/ref.image.php
User avatar
JayBird
Admin
Posts: 4524
Joined: Wed Aug 13, 2003 7:02 am
Location: York, UK
Contact:

Post by JayBird »

use these ready made functions. Just feed it the numbers and it does the rest!

Easy!

http://www.panacode.com/panachart/

Mark
dave420
Forum Contributor
Posts: 106
Joined: Tue Feb 17, 2004 8:03 am

Post by dave420 »

Bech100 - that's not exactly learning PHP :-P

Using the GD library to generate bar graphs (or pie charts, or anything) is ridiculously easy. Just work out the presentation maths, and you're halfway there. Reading the data from the format you've said is trivial, too.

If you want to learn something, use GD. If you want to get it done sooner, use panachart :)
Simon Angell
Forum Commoner
Posts: 45
Joined: Fri Jan 24, 2003 12:14 am

Post by Simon Angell »

thanks, had put this little project on the back burner for now, but i would rather learn it, so GD will be my path of choice - if and when i get around to doing it.....
User avatar
JayBird
Admin
Posts: 4524
Joined: Wed Aug 13, 2003 7:02 am
Location: York, UK
Contact:

Post by JayBird »

dave420 wrote:Bech100 - that's not exactly learning PHP :-P
I aint here to teach, only to help :P

Mark
User avatar
launchcode
Forum Contributor
Posts: 401
Joined: Tue May 11, 2004 7:32 pm
Location: UK
Contact:

Post by launchcode »

Simon - for a simple line chart you don't even need to mess around with GD, you can just use PHP to write out a table with correctly sized cells (or div tags with widths/heights/etc). Just find the highest and lowest points in your data and base everything around that.
Simon Angell
Forum Commoner
Posts: 45
Joined: Fri Jan 24, 2003 12:14 am

Post by Simon Angell »

Hi.
I decided to look at the pana chart, and am currently sorting thorugh the code - decoding it of sorts. now the data input in the test file is like this

Code: Select all

$vCht4 = array(60,40,20,34,5,52,41,20,34,43,64,40);
	$vCht5 = array(12,21,36,27,14,23,3,5,29,23,12,5);
	$vCht6 = array(5,7,3,15,7,8,2,2,2,11,22,3);
	$vLabels = array('Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec');
In the example it is the vCht4 data being used..

I wan't the data to be grabbed from an external source (Temp.log)

In Temp.log the data is written like
9.1,2350
9.0,0000
8.6,0010
etc etc and as i stated before the numbers before the , is the plot ($vCht4)
and after is the label $vLables.

How do i get it to read and parse the temp.log file?

(sorry for asking what is a simple question - id rather get this thing working quickly then going through and changing things when i get time as needed etc etc)
dave420
Forum Contributor
Posts: 106
Joined: Tue Feb 17, 2004 8:03 am

Post by dave420 »

Bech100 - and we thank you! :)
Post Reply