Source for file graphPageviews.php
Documentation is available at graphPageviews.php
require_once './../include/version.php';
require_once './../lib/core.php';
include ('jpgraph/jpgraph.php');
include ('jpgraph/jpgraph_line.php');
include ('jpgraph/jpgraph_date.php');
if ($key < $_GET['movavg']) {
for ($i = 0; $i < $_GET['movavg']; $i++ ) {
$sum += $data[$key - $i];
$item = $sum / $_GET['movavg'];
if (substr($whereSQL, 0, 6) == ' where') {
$whereSQL .= ' and ' . $newCond . ' ';
$whereSQL = ' where ' . $newCond . ' ';
if (isset ($_GET['ip'])) {
buildWhere('phpusertrack_ip.ip="' . $_GET['ip'] . '"');
$text .= ' - ' . $_GET['ip'];
if (isset ($_GET['site'])) {
buildWhere('phpusertrack_data.site_id="' . $_GET['site'] . '"');
$sitenameSQL = "select * from phpusertrack_sites where id=" . $_GET['site'];
$sitename = $db->_query($sitenameSQL);
$text .= ' - ' . $sitename[0]['name'];
if (isset ($_GET['path'])) {
buildWhere('phpusertrack_data.path="' . $_GET['path'] . '"');
$subtitle .= 'Path: ' . $_GET['path'];
if (isset ($_GET['startdate'])) {
buildWhere('phpusertrack_data.timestamp >= "' . $_GET['startdate'] . '"');
$subtitle .= 'Start Date: ' . $_GET['startdate'];
$sql = 'select count(phpusertrack_data.id) as count, UNIX_TIMESTAMP(phpusertrack_data.timestamp) as date from phpusertrack_ip inner join phpusertrack_data on phpusertrack_ip.id=phpusertrack_data.ip_id ' . $whereSQL . ' group by DATE_FORMAT(phpusertrack_data.timestamp, \'%e %b %Y\') order by phpusertrack_data.timestamp asc';
$pageviews = $db->_query($sql);
$movingaverage = array();
foreach ($pageviews as $view) {
// Create the graph. These two calls are always required
$graph = new Graph(500,233);
$graph->img->SetAntiAliasing();
$graph->SetScale("datint");
$graph->yaxis->scale->SetAutoMin(0);
// Adjust the margin a bit to make more room for titles
$graph->img->SetMargin(40,30,22,30);
$graph->xaxis->scale->SetDateAlign(YEARADJ_2);
$graph->xaxis->HideTicks(true,false);
$graph->xaxis->SetTextLabelInterval(5);
$lplot = new LinePlot($data, $xdata);
$lplot->SetFillColor( "#BBCCFF");
if ((isset ($_GET['movavg'])) && ($_GET['movavg'] == true)) {
$mplot = new LinePlot($movingaverage, $xdata);
$mplot->SetColor( "red");
$mplot->SetFillColor( "red@0.95");
$lplot->SetLegend ("Pageviews");
$mplot->SetLegend($_GET['movavg'] . " day Moving Average");
$graph ->legend->SetAbsPos( 50,30,"left" ,"top");
$graph->legend->SetFillColor("#FFFFFF@0.5");
$graph->legend->SetFont(FF_VERA,FS_NORMAL, 7.5);
$graph->legend->SetMarkAbsSize(6);
$graph->yaxis->title->Set("Pageviews");
$graph->title->Set($text);
$graph->subtitle->Set($subtitle);
$graph->title->SetFont(FF_VERA,FS_BOLD, 9);
$graph->subtitle->SetFont(FF_VERA,FS_NORMAL, 8);
$graph->title->SetFont(FF_VERA,FS_BOLD);
$graph->yaxis->title->SetFont(FF_VERA,FS_BOLD, 7);
$graph->xaxis->scale->SetDateFormat('d M Y');
$graph->xaxis->SetTickSide(SIDE_BOTTOM);
$graph->yaxis->HideZeroLabel();
$graph->xaxis->SetPos('min');
$graph->xaxis->scale->ticks->Set (60* 60* 24* 14, 60* 60* 24);
$graph->xaxis->scale->SetDateAlign(DAYADJ_7);
$graph->yaxis->scale->SetGrace(10);
$graph->SetTickDensity (TICKD_DENSE);
$graph->xaxis->SetFont(FF_VERA,FS_NORMAL, 6);
$graph->yaxis->SetFont(FF_VERA,FS_NORMAL, 6);
$graph->xgrid->Show(true ,true);
#list($tickPositions, $minTickPositions) = DateScaleUtils::GetTicks($xdata);
$graph->ygrid->SetFill(true,'#EFEFEF@0.5','#BBCCFF@0.5');
$graph->SetMarginColor("#ffffff");
$graph->xgrid->Show(true, false);
|