Current location: Hot Scripts Forums » Programming Languages » PHP » PHP Graphs


PHP Graphs

Reply
  #1 (permalink)  
Old 04-13-04, 07:25 AM
Apoc's Avatar
Apoc Apoc is offline
Newbie Coder
 
Join Date: Apr 2004
Location: UK
Posts: 41
Thanks: 0
Thanked 0 Times in 0 Posts
PHP Graphs

Time to ask a question. As a bit of a sub project / idea i have (like all my ideas i start and never complete.. whatdidido springs to mind).

But getting back to the question, i have a file, which in the script is processed and inserted into a table. (the file is massive, as its data about my PC temp / voltages).

What i want to do is get this data and be able to select by temp source (i.e. mobo or cpu) and by date and produce a graph. I have hacked some code and got it almost working, but i think the code i have hacked was doing something else (%ages).

So what is the best way to graph say the following data as a line graph?

TEMP
45.5
46.0
47.5
44.5
45.5
45.0
44.0
50.0
49.5
48.5
46.5
39.0

The code i have is the following:

PHP Code:

<?php
//.. Above this is the processing file bit and 
//..the DB reult bit (selecting from the DB)
//..That all works fine
 
header ("Content-type: image/jpeg"); 

// --- Need to figure out width and size of the font. 
$font 1
$fontHeight ImageFontHeight ($font); 
$fontWidth ImageFontWidth ($font); 

// --- This is the number of rows 
$numAnswers mysql_num_rows ($resulters); 
echo 
$numanswers
// --- This is the size of the image 
$width 1200//300 
$height 300//200 
$image ImageCreate ($width$height); 

// --- Get the width of each item. 
$widthPerItem = ($width $numAnswers); 

$white ImageColorAllocate ($image255255255); 
$red ImageColorAllocate ($image25500); 

//$top = 10; 
$top 70
$bottom $height - ($fontHeight); 
$maxbarheight $bottom $top
$item 0
$gap 5
while (
$row mysql_fetch_array ($resultersMYSQL_ASSOC)) { 

// --- Calcualate the pixel height 
if ($mostVotes 0) { 
$newtop $bottom 
((
$row["Tmp2"] * $maxbarheight) / $mostVotes); 
} else { 
$newtop $bottom


// --- Draw each bar graph 
ImageFilledRectangle ($image
(
$item $widthPerItem) + ($gap 2), 
$newtop
(
$item $widthPerItem) + ($widthPerItem - ($gap 2)), 
$bottom$red); 

$text $row["Time"]; 

ImageString ($image$font
$item $widthPerItem
$bottom $fontHeight$text$red); 

$item++; 



ImageJpeg ($image); 
ImageDestroy ($image); 
?>

The bit of the code that bothers me is:
PHP Code:

//$top = 10; 
$top 70
$bottom $height - ($fontHeight); 
$maxbarheight $bottom $top
$item 0
$gap 5
while (
$row mysql_fetch_array ($resultersMYSQL_ASSOC)) { 

// --- Calcualate the pixel height 
if ($mostVotes 0) { 
$newtop $bottom 
((
$row["Tmp2"] * $maxbarheight) / $mostVotes); 
} else { 
$newtop $bottom

As i can't work out what its doing (was for some polling thing), it doesn't work with a small pic size i.e. 400*80 which i want (sig time) but will work (or seems to work) with picture sizes of 15000*100. The data is taken every 5min so thats about 300 values of data per day.

Any ideas on how to do this, i.e. plat on make a line graph of the data?

Cheers
__________________
-
< ? $Apoc ? >
-

If it aint broke, let Apoc fix it for you.

If all else fails, hack it until it works.
Reply With Quote
  #2 (permalink)  
Old 04-14-04, 02:29 AM
fie fie is offline
Newbie Coder
 
Join Date: Mar 2004
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
it would have help to have samples of the fscked up images
Reply With Quote
  #3 (permalink)  
Old 04-14-04, 04:43 PM
Apoc's Avatar
Apoc Apoc is offline
Newbie Coder
 
Join Date: Apr 2004
Location: UK
Posts: 41
Thanks: 0
Thanked 0 Times in 0 Posts
Been having a play and altered the code substantially to whats above (instead of hacking i made my own version). what it ddoes now is select the array from mysql, and plot a line from point n to n+1 and then loops for all the variables. this is nearly working. When its done i'll post the code incase its of use to anyone else.
__________________
-
< ? $Apoc ? >
-

If it aint broke, let Apoc fix it for you.

If all else fails, hack it until it works.
Reply With Quote
  #4 (permalink)  
Old 04-15-04, 03:39 AM
Apoc's Avatar
Apoc Apoc is offline
Newbie Coder
 
Join Date: Apr 2004
Location: UK
Posts: 41
Thanks: 0
Thanked 0 Times in 0 Posts
Sorted.. what you guys think?
__________________
-
< ? $Apoc ? >
-

If it aint broke, let Apoc fix it for you.

If all else fails, hack it until it works.
Reply With Quote
  #5 (permalink)  
Old 04-17-04, 03:18 AM
snipe's Avatar
snipe snipe is offline
New Member
 
Join Date: Apr 2004
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Quote:
Originally Posted by Apoc
Sorted.. what you guys think?
Have you checked out JPGraph at all? Its *amazing*.

http://www.aditus.nu/jpgraph/

I have used it for many things, very quick and easy, and super-flexible.
__________________
-- snipe
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
PHP and MySQL ? rob2132 Hot Scripts Forum Questions, Suggestions and Feedback 4 08-29-08 02:22 AM
PHP Dudes - Hi All stuart New Members & Introductions 4 05-03-04 01:22 PM
100 Web Templates & 10 PHP Scripts for sale! HostersUK.co.uk General Advertisements 0 01-10-04 12:31 AM
Realtime PHP Code Obfuscation barrywien General Advertisements 1 11-16-03 06:50 PM
How to convert php generated pages to SE friendly HTML or PHP(SE friendly) -CLASS 101 crippled PHP 1 11-16-03 06:37 AM


All times are GMT -5. The time now is 10:26 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.