Leitgedanken/graph_user.php
2022-11-21 09:47:28 +01:00

122 lines
3.0 KiB
PHP

<?php
/*
# Fuer debugging
error_reporting(E_ALL);
ini_set('display_errors', 1);
#echo __LINE__."<br>";
*/
require_once("config/datenbankanbindung.php"); // f&uuml;gt die Datenbankanbindung ein: Sys:\php\includes\kurs\datenbankanbindung.php
#require ("./jpgraph/jpgraph.php");
#require ("./jpgraph/jpgraph_bar.php");
#require ("./jpgraph/jpgraph_line.php");
require ("./jpgraph/src/jpgraph.php");
require ("./jpgraph/src/jpgraph_bar.php");
require ("./jpgraph/src/jpgraph_line.php");
$db = dbconnect();
$result2 = $db->query("SELECT count(*) multiplikator
FROM userlog,admin
WHERE admin.user= userlog.uid
GROUP BY userlog.uid");
$row2 = $result2->fetch_array();
$height= 16*$row2['multiplikator'];
$query = "SELECT vorname, nachname, count(ip) anz
FROM userlog,admin
WHERE admin.user= userlog.uid
AND admin.inaktiv !='J'
GROUP BY userlog.uid
ORDER BY anz desc, nachname asc
";
$result = $db->query( $query)
or die ("Cannot execute query");
while ($row = $result->fetch_array()){
$ydata[] = $row['anz'];
$ydata2[] = $row['anz'];
$months[] = "$row[vorname] $row[nachname] ($row[anz])";
}
// Some "random" data ## Balken und Linien
#$ydata = $data;
#$ydata2 = $data;
#exit;
// Get a list of month using the current locale
#$months = $gDateLocale->GetShortMonth();
#$months = array('1','3');
// Create the graph.
$graph = new Graph(800,$height);
$graph->SetScale("textlin"); # automatische Bemaßung
$graph->SetMarginColor('white');
// Adjust the margin slightly so that we use the
// entire area (since we don't use a frame)
$graph->Set90AndMargin(180,10,50,10); # es empfiehlt sich immer was anzugeben, da bei 0 eine ungeschickte autoskalierung zur Anwendung kommt
// Box around plotarea
$graph->SetBox();
// No frame around the image
$graph->SetFrame(false);
// Setup the tab title
$graph->title->Set('Besuchsstatistik pro User');
$graph->title->SetFont(FF_ARIAL,FS_BOLD,12);
// Setup the X and Y grid
$graph->ygrid->SetFill(true,'#EFEFEF@0.5','#BBCCFF@0.5');
$graph->ygrid->Show();
$graph->xgrid->Show();
// Setup month as labels on the X-axis
$graph->xaxis->SetTickLabels($months);
$graph->xaxis->SetFont(FF_ARIAL,FS_NORMAL,9);
$graph->xaxis->SetLabelAlign('right','center','center');
#$graph->xaxis->SetLabelAngle(45);
$graph->yaxis->SetFont(FF_ARIAL,FS_NORMAL,9);
// Create a bar pot
$bplot = new BarPlot($ydata);
$bplot->SetWidth(0.6);
$fcol='#440000';
$tcol='#FF9090';
$bplot->SetFillGradient($fcol,$tcol,GRAD_LEFT_REFLECTION);
// Set line weigth to 0 so that there are no border
// around each bar
$bplot->SetWeight(1);
$graph->Add($bplot);
// Create filled line plot
$lplot = new LinePlot($ydata2);
$lplot->SetFillColor('skyblue@0.7');
$lplot->SetColor('navy@0.5');
$lplot->SetBarCenter();
$lplot->mark->SetType(MARK_SQUARE);
$lplot->mark->SetColor('blue@0.7');
$lplot->mark->SetFillColor('lightblue');
$lplot->mark->SetSize(3);
$graph->Add($lplot);
// .. and finally send it back to the browser
$graph->Stroke();
?>