Jump to content

Display Information Graph


clanstyles

Recommended Posts

  • Replies 66
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

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 .. :D

Link to comment
Share on other sites

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);
?>

Link to comment
Share on other sites

you forgot a { :P

 

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 />

 

 

Link to comment
Share on other sites

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);
?>

Link to comment
Share on other sites

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)

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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++;
}
?>

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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!!

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.