cooldude832 Posted June 28, 2007 Share Posted June 28, 2007 $graphValues = $row['size']; just change it to $graphValues[$row['serverid']] = $row['size']; that way you can have each one on its own array. then when you use them in the actual graph drawing you make sure you say $graphValues[1] or $graphValues[2]; Quote Link to comment Share on other sites More sharing options...
clanstyles Posted June 28, 2007 Author Share Posted June 28, 2007 Thank You, So should this all work. <? include("config.php"); $graphValues = Array(); // Define .PNG image header("Content-type: image/png"); $imgWidth=250; $imgHeight=250; $result = mysql_query("SELECT size,timestamp FROM `serverInfo`") or die(mysql_error()); while( $row= mysql_fetch_array($result)){ $sizes[$row['timestamp']][] = $row['size']; } foreach($sizes as $key => $value) { $tempcount = count($value); $average[$key] = array_sum($value)/$tempcount; //$graphValues = array_merge($graphValues, $key); $graphValues[$row['serverid']] = $row['size']; //echo "Average for ".$key.": ".$average[$key]."<br/>"; } // Create image and define colors $image=imagecreate($imgWidth, $imgHeight); $colorWhite=imagecolorallocate($image, 255, 255, 255); $colorGrey=imagecolorallocate($image, 192, 192, 192); $colorBlue=imagecolorallocate($image, 0, 0, 255); // Create border around image imageline($image, 0, 0, 0, 250, $colorGrey); imageline($image, 0, 0, 250, 0, $colorGrey); imageline($image, 249, 0, 249, 249, $colorGrey); imageline($image, 0, 249, 249, 249, $colorGrey); //imagefttext($image, 12.0, 12.0, 0, 0, 0, "", "12"); // Create grid for ($i=1; $i<11; $i++){ imageline($image, $i*25, 0, $i*25, 250, $colorGrey); imageline($image, 0, $i*25, 250, $i*25, $colorGrey); } foreach($sizes[$timestamp] as $value) { $node[] = $value; } foreach($graphValues as $value) { // Create line graph for ($i=0; $i<10; $i++) { //imageline($image, $i*25, (250-$graphValues[$i]), ($i+1)*25, (250-$graphValues[$i+1]), $colorBlue); imageline($image, $i*25, (250-$graphValues[$i]), ($i+1)*25, (250-$graphValues[$i+1]), $colorBlue); } } // Output graph and clear image from memory imagepng($image); imagedestroy($image); ?> That is what I have in the end from all the changes .. Quote Link to comment Share on other sites More sharing options...
clanstyles Posted June 28, 2007 Author Share Posted June 28, 2007 Rofl mine doesn't work **CRYS** Quote Link to comment Share on other sites More sharing options...
cooldude832 Posted June 28, 2007 Share Posted June 28, 2007 give me a sec you code is very broke you can't just copy and paste it gotta work it in smartly Quote Link to comment Share on other sites More sharing options...
cooldude832 Posted June 28, 2007 Share Posted June 28, 2007 Try this: Untested, but it will draw 2 lines one for each server <? include("config.php"); // Define .PNG image header("Content-type: image/png"); $imgWidth=250; $imgHeight=250; $result = mysql_query("SELECT size,timestamp,serverid FROM `serverInfo`") or die(mysql_error()); while( $row= mysql_fetch_array($result)){ $temptime = str_replace(", ","",$value['timestamp']); $sizes[$temptime][] = $row['size']; $graphValues[$row['serverid']] = $row['size']; } foreach($sizes as $key => $value) { $tempcount = count($value); $average[$key] = array_sum($value)/$tempcount; //$graphValues = array_merge($graphValues, $key); $graphValues[$row['serverid']] = $row['size']; //echo "Average for ".$key.": ".$average[$key]."<br/>"; } // Create image and define colors $image=imagecreate($imgWidth, $imgHeight); $colorWhite=imagecolorallocate($image, 255, 255, 255); $colorGrey=imagecolorallocate($image, 192, 192, 192); $colorBlue=imagecolorallocate($image, 0, 0, 255); // Create border around image imageline($image, 0, 0, 0, 250, $colorGrey); imageline($image, 0, 0, 250, 0, $colorGrey); imageline($image, 249, 0, 249, 249, $colorGrey); imageline($image, 0, 249, 249, 249, $colorGrey); //imagefttext($image, 12.0, 12.0, 0, 0, 0, "", "12"); // Create grid for ($i=1; $i<11; $i++){ imageline($image, $i*25, 0, $i*25, 250, $colorGrey); imageline($image, 0, $i*25, 250, $i*25, $colorGrey); } $srvcount = 1; $numservers = 2; while ($srvcount <=$numservers) foreach($graphValues[$srvcount] as $value) { // Create line graph for ($i=0; $i<10; $i++) { //imageline($image, $i*25, (250-$graphValues[$srvcount][$i]), ($i+1)*25, (250-$graphValues[$srvcount][$i+1]), $colorBlue); imageline($image, $i*25, (250-$graphValues[$srvcount][$i]), ($i+1)*25, (250-$graphValues[$srvcount][$i+1]), $colorBlue); } } $srvcount++; } // Output graph and clear image from memory imagepng($image); imagedestroy($image); ?> Quote Link to comment Share on other sites More sharing options...
clanstyles Posted June 28, 2007 Author Share Posted June 28, 2007 you forgot a { Also, na its not showing the acutal line..Idk why... :-/ I hate arrays there hard for me in every lanague. I can do One. But once it gets to like an array inside of another or some trippy shit. It gets hard..idkwhy When I put that b racket there it saids: <b>Warning</b>: Invalid argument supplied for foreach() in <b>/mnt/backside/vol/skyblue/spunky/hyp3r/gungame.cswiki.org/technicolor/graph.php</b> on line <b>45</b><br /> <br /> <b>Warning</b>: Invalid argument supplied for foreach() in <b>/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxgraph.php</b> on line <b>45</b><br /> Quote Link to comment Share on other sites More sharing options...
cooldude832 Posted June 28, 2007 Share Posted June 28, 2007 can i have a copy of your config file cause I don't have your color pallette and its erroring fo rme Quote Link to comment Share on other sites More sharing options...
cooldude832 Posted June 28, 2007 Share Posted June 28, 2007 I've got it working up to the line, but the issue with the line is you have only 1 value ($size) for your lines. Are you just evenly spacing out the $size with respect to time? Quote Link to comment Share on other sites More sharing options...
clanstyles Posted June 28, 2007 Author Share Posted June 28, 2007 No im not sure lol .. its a shot in the dark. Quote Link to comment Share on other sites More sharing options...
cooldude832 Posted June 28, 2007 Share Posted June 28, 2007 one sec cause i'm having to resize it to fit a 250x250 box cause your range on size is between 0-1000 Quote Link to comment Share on other sites More sharing options...
cooldude832 Posted June 28, 2007 Share Posted June 28, 2007 Alright I got it working, its not a line but an X/Y Scatter Give me the url you have it on so I can see: <?php // Define .PNG image header("Content-type: image/png"); $imgWidth=250; $imgHeight=250; $result = mysql_query("SELECT size,timestamp,serverid FROM `serverInfo`") or die(mysql_error()); while( $row= mysql_fetch_array($result)){ $temptime = str_replace(", ","",$row['timestamp']); $sizes[$temptime][] = $row['size']; $graphValues[$row['serverid']][] = $row['size']; } // Create image and define colors $image=imagecreate($imgWidth, $imgHeight) or die ("GD ERROR"); $colorWhite=imagecolorallocate($image, 255, 255, 255); $colorGrey=imagecolorallocate($image, 192, 192, 192); $colorBlue=imagecolorallocate($image, 0, 0, 255); // Create border around image imageline($image, 0, 0, 0, 250, $colorGrey); imageline($image, 0, 0, 250, 0, $colorGrey); imageline($image, 249, 0, 249, 249, $colorGrey); imageline($image, 0, 249, 249, 249, $colorGrey); //imagefttext($image, 12.0, 12.0, 0, 0, 0, "", "12"); // Create grid for ($i=1; $i<11; $i++){ imageline($image, $i*25, 0, $i*25, 250, $colorGrey); imageline($image, 0, $i*25, 250, $i*25, $colorGrey); } $srvcount = 1; $numservers = 2; while ($srvcount <=$numservers) { if($srvcount == "1"){$color =imagecolorallocate($image, 192, 192, 192);} else{$color = imagecolorallocate($image, 0, 0, 255);} $x1 = 0; foreach($graphValues[$srvcount] as $value) { $x1 = $x1+22; $x2 = $x1+5; $y1 = $value/4; $y2 = $y1+10; imagefilledrectangle($image, $x1, $y1, $x2, $y2, $color); } $srvcount++; } // Output graph and clear image from memory imagepng($image); imagedestroy($image); ?> Quote Link to comment Share on other sites More sharing options...
clanstyles Posted June 28, 2007 Author Share Posted June 28, 2007 I don't know how to say this, Im sorry to report I really want this to work. I feel like im pushing you lol.. Thanks again in advanced! <b>Warning</b>: Invalid argument supplied for foreach() in <b>/mnt/backside/vol/skyblue/spunky/hyp3r/gungame.cswiki.org/technicolor/graph.php</b> on line <b>39</b><br /> --- > foreach($graphValues[$srvcount] as $value) Quote Link to comment Share on other sites More sharing options...
clanstyles Posted June 28, 2007 Author Share Posted June 28, 2007 Ive been playing with it if you take out the <= in the while loop it kinda fixes it... You can see here http://gungame.cswiki.org/technicolor/graph.php Quote Link to comment Share on other sites More sharing options...
cooldude832 Posted June 28, 2007 Share Posted June 28, 2007 I've got this: http://pira00.worldispnetwork.com/testing2.php and that seems to work great when its not an image, but as soon as it goes into an image it fails saying error and it don't tell me the image errors Quote Link to comment Share on other sites More sharing options...
clanstyles Posted June 28, 2007 Author Share Posted June 28, 2007 Mabye you don't have to.. imagepstext($image, "TEXT", " FONT", $intsize, $intforeground, $intbackgground, $ingxcord, $intycord); there is an image function availbe to write on the image, on your end have it write out the image values Try th at. Quote Link to comment Share on other sites More sharing options...
cooldude832 Posted June 28, 2007 Share Posted June 28, 2007 I got it tell me how i tlooks <?php // Define .PNG image header("Content-type: image/png"); $imgWidth=250; $imgHeight=250; $result = mysql_query("SELECT size,timestamp,serverid FROM `serverInfo`") or die(mysql_error()); while( $row= mysql_fetch_array($result)){ $temptime = str_replace(", ","",$row['timestamp']); $sizes[$temptime][] = $row['size']; $graphValues[$row['serverid']][] = $row['size']; } // Create image and define colors $image=imagecreate($imgWidth, $imgHeight) or die ("GD ERROR"); $colorWhite=imagecolorallocate($image, 255, 255, 255); $colorGrey=imagecolorallocate($image, 192, 192, 192); $colorBlue=imagecolorallocate($image, 0, 0, 255); // Create border around image imageline($image, 0, 0, 0, 250, $colorGrey); imageline($image, 0, 0, 250, 0, $colorGrey); imageline($image, 249, 0, 249, 249, $colorGrey); imageline($image, 0, 249, 249, 249, $colorGrey); //imagefttext($image, 12.0, 12.0, 0, 0, 0, "", "12"); // Create grid for ($i=1; $i<11; $i++){ imageline($image, $i*25, 0, $i*25, 250, $colorGrey); imageline($image, 0, $i*25, 250, $i*25, $colorGrey); } $srvcount = 1; $numservers = 2; while ($srvcount <=$numservers) { if($srvcount == "1"){$color =imagecolorallocate($image, 192, 192, 192);} else{$color = imagecolorallocate($image, 0, 0, 255);} $x1 = 0; $j = 0; $x2 = 0; $numpoints = count($graphValues[$srvcount])-1; while ($j < $numpoints) { $k = $j+1; $x1 = $x2+20; $x2 = $x1+10; $y1 = $graphValues[$srvcount][$j]/4; $y2 = $graphValues[$srvcount][$k]; imageline($image, $x1, $y1, $x2, $y2, $color); $j++; } $srvcount++; } // Output graph and clear image from memory imagepng($image); imagedestroy($image); ?> edit: make sure the /4 is in the $y1 part Quote Link to comment Share on other sites More sharing options...
cooldude832 Posted June 28, 2007 Share Posted June 28, 2007 okay finally got it to connect the lines and look amazing try this while part at the bototm <?php while ($srvcount <=$numservers) { if($srvcount == "1"){$color =imagecolorallocate($image, 192, 192, 192);} else{$color = imagecolorallocate($image, 0, 0, 255);} $j = 0; $x[0] = 0; $y[0] = 0; $numpoints = count($graphValues[$srvcount])-1; while ($j < $numpoints) { $k = $j+1; $x[$j] = $x[$j]; $x[$k] = $x[$j]+50; $y[$j] = $graphValues[$srvcount][$j]/4; $y[$k] = $graphValues[$srvcount][$k]/4; imageline($image, $x[$j], $y[$j], $x[$k], $y[$k], $color); $j++; } $srvcount++; } ?> Quote Link to comment Share on other sites More sharing options...
cooldude832 Posted June 28, 2007 Share Posted June 28, 2007 Note thats a 50 px spacing between each node change the line $x[$k] = $x[$j]+50; change the 50 to what ever spacing you so desire. Quote Link to comment Share on other sites More sharing options...
clanstyles Posted June 28, 2007 Author Share Posted June 28, 2007 You might have it http://gungame.cswiki.org/technicolor/graph.php Check it out... Idk looks good to me but I would have to check accuracy now More bs upload time! Quote Link to comment Share on other sites More sharing options...
cooldude832 Posted June 28, 2007 Share Posted June 28, 2007 its all scrunched up something ain't write in your copy Quote Link to comment Share on other sites More sharing options...
cooldude832 Posted June 28, 2007 Share Posted June 28, 2007 I see that now, but tell me what your values for size are. Basically you need to translate the range for $sizes say its from 1-10000 to a scael from 0-250 by some weighing factor i had a weighing factor of 1/4 because my fake values where between 0-1000 so 1000/4 = 250 so for you do whatever $size[max]/x=250 gives you and change the 4 to x Quote Link to comment Share on other sites More sharing options...
clanstyles Posted June 28, 2007 Author Share Posted June 28, 2007 Okay now look, been puting data in. Looks like it works! <3 U!!! OMG!! 1 more thing I need to make thos over a 12 month span now :-/ i know im so sorry. And file size is in ( Bytes ). And the folders its giong to be monnitoring are TB's big so I need like to increase the top size a lot.. How can I do that, what numbers lol. THANK YOU!! Quote Link to comment Share on other sites More sharing options...
cooldude832 Posted June 28, 2007 Share Posted June 28, 2007 Well i think you've got the just of it now. You probably are going to want to resize the image to a 500x500 area. Since 12 months is going to be alot of data. I'm working on a test for that scale factor so it auto scales down the lines to fit your graphical area. Quote Link to comment Share on other sites More sharing options...
clanstyles Posted June 28, 2007 Author Share Posted June 28, 2007 kk Thank You so much A+++ Quote Link to comment Share on other sites More sharing options...
cooldude832 Posted June 28, 2007 Share Posted June 28, 2007 try this; <?php while ($srvcount <=$numservers) { arsort($graphValues[$srvcount]); $maxsize = current($graphValues[$srvcount]); $scale = $maxsize/250; if($srvcount == "1"){$color =imagecolorallocate($image, 192, 192, 192);} else{$color = imagecolorallocate($image, 0, 0, 255);} $j = 0; $x[0] = 0; $y[0] = 0; $numpoints = count($graphValues[$srvcount])-1; while ($j < $numpoints) { $k = $j+1; $x[$j] = $x[$j]; $x[$k] = $x[$j]+50; $y[$j] = round($graphValues[$srvcount][$j]/$scale); $y[$k] = round($graphValues[$srvcount][$k]/$scale); imageline($image, $x[$j], $y[$j], $x[$k], $y[$k], $color); $j++; } $srvcount++; } ?> It auto sizes each line Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.