Здравейте,
Имам проблем с отчитането на посещаемост на гейм сървър.. Имам код за целта, но при повече потребители онлайн графата отива по-надолу, вместо обратното.. Не съм сигурен, че мога да го обсяня точно, за това давам снимка.
http://i.imgur.com/QSPbZ.jpg
При по-голяма цифра, трябва точката да е по-горе.. А не мога да го направя :Х
Ето и кода
Имам проблем с отчитането на посещаемост на гейм сървър.. Имам код за целта, но при повече потребители онлайн графата отива по-надолу, вместо обратното.. Не съм сигурен, че мога да го обсяня точно, за това давам снимка.
http://i.imgur.com/QSPbZ.jpg
При по-голяма цифра, трябва точката да е по-горе.. А не мога да го направя :Х
Ето и кода
Код:
<?php
date_default_timezone_set('Europe/Sofia');
mysql_connect('localhost', 'root', NULL) or die (mysql_error());
mysql_select_db('test');
$query = mysql_query("SELECT * FROM `pvpgn_userstat` ORDER BY date ASC LIMIT 24") or die (mysql_error());
list($UsersSum, $GamesSum) = mysql_fetch_row(mysql_query("SELECT SUM(`users`), SUM(`games`) FROM `pvpgn_userstat`")) or die (mysql_error());
header ("Content-type: image/jpg");
function percent($part, $full)
{
return ($part / $full) * 100;
}
$pxBetween = 40;
$x_gap = 40;
$x_max = ($x_gap * 24) + 50;
$y_max = 250;
$image = @ImageCreate ($x_max, $y_max) or die ("Cannot Initialize new GD image stream");
$background_color = ImageColorAllocate ($image, 234, 234, 234);
$graph_color = ImageColorAllocate ($image,25,25,25);
$users_color = ImageColorAllocate ($image, 233, 14, 91);
$games_color = ImageColorAllocate ($image, 0, 102, 153);
$border_color = ImageColorAllocate ($image, 0, 0, 0);
$absoluteWidth = 10;
$absoluteHeight = 220;
while($array = mysql_fetch_assoc($query))
{
$users = $array['users'];
$games = $array['games'];
$NewUserHeight = percent($users, $UsersSum) * 40;
$NewGamesHeight = percent($games, $GamesSum) * 50;
if($NewUserHeight > 200)
$NewUserHeight = 200;
elseif($NewUserHeight < 85)
$NewUserHeight = 85;
if($NewGamesHeight > 210)
$NewGamesHeight = 210;
elseif($NewGamesHeight < 170)
$NewGamesHeight = 170;
ImageString($image, 3, $absoluteWidth, $NewUserHeight - 75, $users, $users_color);
ImageString($image, 3, $absoluteWidth, $NewGamesHeight, $games, $games_color);
ImageString($image, 3, $absoluteWidth, ($y_max - 15), date('H', $array['date']), $border_color);
if(isset($firstLine))
{
imageline($image, $absoluteWidth, $NewUserHeight - 75, $previousWidth, $previousUsersHeight - 75, $users_color);
imageline($image, $absoluteWidth, $NewGamesHeight, $previousWidth, $previousGamesHeight, $games_color);
}
$previousUsersHeight = $NewUserHeight;
$previousGamesHeight = $NewGamesHeight;
$previousWidth = $absoluteWidth;
$absoluteWidth = $absoluteWidth + $pxBetween;
$firstLine = false;
}
ImageString($image, 3, ($x_max - 40), ($y_max / 2), 'Users', $users_color);
ImageString($image, 3, ($x_max - 40), (($y_max / 2) + 35), 'Games', $games_color);
imageline($image, 0, 150, ($x_max - 50), 150, $border_color);
imageline($image, 0, ($y_max - 20), ($x_max - 50), ($y_max - 20), $border_color);
imageline($image, ($x_max - 50), ($y_max - 20), ($x_max - 50), 0, $border_color);
ImageJPEG($image);
?>