Jump to content

Display Information Graph


clanstyles

Recommended Posts

Okay guys, I have no idea in hell how to do this somebody at least point me in the right direction. I know its possible.

 

I need something like Alexa.com

 

It generates a graph and shows stats on it over time. I know its just an image they use that they write on. How do you go about doing this? How do you make the lines?

 

Thank You

Link to comment
Share on other sites

  • Replies 66
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

Thx :D Yeah found a tutorial. its really easy :P

 

Next problem im having with this. I have "dates" in a field. I need to organize them.

 

I have a table:

id, serverid, size, dirname, timestamp

 

For every timestamp that is the same I need to average the entire one out WHILE the serverid is == what ever its on. Thats not the hard part I can't figure out how to do the timestamp part.

 

It is in the format of mm/d/y

it has to do with Foreach i would think. I'm not to sure though.

 

ThanK You

Link to comment
Share on other sites

average the time stamps??? best idea I got would be to convert them to UNIX seconds since Epoch average that then convert that to a timestamp

 

No not average them but like..Heres an example:

 

(id, serverid, size, dir, timestamp)

FakeData:

1, 1, 500, "FoldersRock", "05, 28, 2007"

2, 1, 123, "FoldersRock1", "05, 28, 2007"

3, 1, 543, "FoldersRock2", "05, 28, 2007"

 

4, 1, 6764, "FoldersRock3", "05, 25, 2007"

5, 1, 345677, "FoldersRock4", "05, 25, 2007"

6, 1, 3, "FoldersRock5", "05, 25, 2007"

-----------------------------------------

7, 2, 500, "FoldersRock", "05, 28, 2007"

8, 2, 123, "FoldersRock1", "05, 28, 2007"

9, 2, 543, "FoldersRock2", "05, 28, 2007"

 

10 2, 6764, "FoldersRock3", "05, 25, 2007"

11, 2, 345677, "FoldersRock4", "05, 25, 2007"

12, 2, 3, "FoldersRock5", "05, 25, 2007"

 

Now with this information...Average all the "Size" fields that are the same as the date. So like all the "05, 28, 2007";s on SERVER1 are the same

Then all the "05, 28, 2007" on server2 must be averaged but it goes for every date.

 

so then the "05, 25, 2007" go next

 

Link to comment
Share on other sites

try:

<?php

$result = mysql_query("SELECT size,timestamp FROM `tablename`");
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;
echo "Average for ".$key.": ".$average[$key]."<br/>";
}
?>

 

edit:

the while function gathers all the info from the table and then organizes them by date

the foreach takes each date and then averages and displays its average  This only works for 1 table if you have a second copy and paste the whole while function and change the table name. It will just append to the array accordingly

Link to comment
Share on other sites

<?
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;
array_merge($graphValues, $key);
//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);
}

// Create line graph
for ($i=0; $i<10; $i++){
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);
?>

 

This prints out nothing..

Link to comment
Share on other sites

This works on my server with the dummy data.  (same as you would get from the mysql.) Below this is one that should work.

<?php
$data[1]['size'] = 500;
$data[1]['timestamp'] = "05, 28, 2007";
$data[2]['size'] = 475;
$data[2]['timestamp'] = "05, 28, 2007";
$data[3]['size'] = 354;
$data[3]['timestamp'] = "05, 26, 2007";
$data[4]['size'] = 184;
$data[4]['timestamp'] = "05, 26, 2007";
$data[5]['size'] = 654;
$data[5]['timestamp'] = "05, 26, 2007";
$data[6]['size'] = 475;
$data[6]['timestamp'] = "05, 27, 2007";
$data[7]['size'] = 321;
$data[7]['timestamp'] = "05, 27, 2007";
$data[8]['size'] = 875;
$data[8]['timestamp'] = "05, 27, 2007";
$data[9]['size'] = 552;
$data[9]['timestamp'] = "05, 27, 2007";
$data[0]['size'] = 123;
$data[0]['timestamp'] = "05, 27, 2007";

foreach ($data as $value)
{
$temptime = str_replace(", ","",$value['timestamp']);
$sizes[$temptime][] = $value['size']; 
}

foreach($sizes as $key => $value){

$tempcount = count($value);
$average[$key] = array_sum($value)/$tempcount;
echo "Average for ".$key.": ".$average[$key]."<br/>";
}
?>

 

Good one

<?php
$result = mysql_query("SELECT size,timestamp FROM `tablename`");
while( $row= mysql_fetch_array($result)){
$temptime = str_replace(", ","",$value['timestamp']);
$sizes[$temptime][] = $value['size']; 
}

foreach($sizes as $key => $value){

$tempcount = count($value);
$average[$key] = array_sum($value)/$tempcount;
echo "Average for ".$key.": ".$average[$key]."<br/>";
}
?>

 

You will have to re space out the times in post

Link to comment
Share on other sites

if you have php 5 this will work to space out the dates again

$tempkey = str_split($key);

$key = $tempkey[0];

$key .= $tempkey[1];

$key .= " ";

$key .= $tempkey[2];

$key .= $tempkey[3];

$key .= " ";

$key .=$tempkey[4];

$key .=$tempkey[5];

$key .=$tempkey[6];

$key .=$tempkey[7];

 

what do you mean each time?

Link to comment
Share on other sites

Well whats going to happen is this script I made runs at midnight and logs all this info into serverInfo ( I showed you the fields ). It includes the date. This graph is supposed to show over time. So if each date is seperate it can show it better over time.

Link to comment
Share on other sites

I think I'm understanding, but let me get this right.  You are saying since the queries are placed into the table in a time ordred fashioned (IE one at 10 am one at 12pm one at 2 pm etc etc) that you would like to have each one be an individual node on your graph.  Well to answer your question that is possible.  because all the data is  in the array $size[The Day][Counting Number] they should ideally be in time order.  so you can just say

 

foreach($sizes[$timestamp] as $value)

{

$node[] = $value;

}

 

if that makes any sense.

Link to comment
Share on other sites

Yeah I think I get it, thank you! Ill try that now. :D

 

Wait Im lost lol

 

imageline($image, $i*25, (250-$graphValues[$i]),  ($i+1)*25,  (250-$graphValues[$i+1]), $colorBlue);

 

I need to make a new line for each one. And how is that above code going to help me with this?

 

Thanks :D

Link to comment
Share on other sites

something is being stupid for me, but this is what i got going;

<?php
$keys = array_keys($sizes);
foreach ($keys as $value)
{
if ($initalized == "yes")
{$grapharrays .= ", ";}
else
{$initalized = "yes";}
$grapharrays .= "\$sizes[";
$grapharrays .= $value;
$grapharrays .= "]";
}
$graphvalues = array_merge($grapharrays);
print_r($graphvalues);
?>

which should work, but some reason its taking the string i have of array values as a string and not the arrays it needs to merge

Link to comment
Share on other sites

best idea here though is to expand your timestamp to a full YYYY-MM-DD-HH-MM-SSSS and then on the query say ORDER BY timestamp and then there is no worries at all.  then however you will have to do more adjustment to the string but i can show you that if you thinkin gabout going that way

Link to comment
Share on other sites

Ill be happy to change that. But what I would like in the end of all this is for it to be like this.

 

I have a table of servers

CREATE TABLE `servers` (
  `id` int(11) NOT NULL auto_increment,
  `name` text,
  `keyfile` text NOT NULL,
  `password` text NOT NULL,
  `enabled` tinyint(1) NOT NULL,
  PRIMARY KEY  (`id`)
) ENGINE=MyISAM AUTO_INCREMENT=11 DEFAULT CHARSET=latin1;

 

So if I have two servers, on the graph there needs to be two lines. in serverInfo the field serverid = 1 so tin the table servers it needs to make sure theres a line for that server and average it out ever day.

 

There is a cronjob to index dir info ( have all this done already ). It logs it by date.

 

Does this make more sense?

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.