Source for file graphDailyPageviews.php
Documentation is available at graphDailyPageviews.php
require_once './../include/version.php';
require_once './../lib/core.php';
include ('jpgraph/jpgraph.php');
include ('jpgraph/jpgraph_bar.php');
include ('jpgraph/jpgraph_date.php');
if (substr($whereSQL, 0, 6) == ' where') {
$whereSQL .= ' and ' . $newCond . ' ';
$whereSQL = ' where ' . $newCond . ' ';
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'];
buildWhere('phpusertrack_data.timestamp >= "' . date('Y-m-01 00:00:00') . '"');
$sql = 'select count(phpusertrack_data.id) as count, DATE_FORMAT(phpusertrack_data.timestamp, \'%e\') as date, count(distinct phpusertrack_ip.id) as visits from phpusertrack_ip inner join phpusertrack_data on phpusertrack_ip.id=phpusertrack_data.ip_id ' . $whereSQL . ' group by DATE_FORMAT(phpusertrack_data.timestamp, \'%d\') order by DATE_FORMAT(phpusertrack_data.timestamp, \'%d\') asc';
$pageviews = $db->_query($sql);
$movingaverage = array();
foreach ($pageviews as $page) {
$data[$page['date'] - 1] = $page['count'];
$data2[$page['date'] - 1] = $page['visits'];
for ($i = 0; $i < date('t'); $i++ ) {
// Create the graph. These two calls are always required
$width = count($xdata) * 50;
} else if ($width > 1000) {
$graph = new Graph($width,233);
$graph->img->SetAntiAliasing();
$graph->SetScale("textlin");
$graph->yaxis->scale->SetAutoMin(0);
// Adjust the margin a bit to make more room for titles
$graph->img->SetMargin(40,10,10,30);
//$graph->xaxis->HideTicks(true,false);
//$graph->xaxis->SetTextLabelInterval(5);
$lplot = new BarPlot($data);
$lplot->SetLegend("Pageviews");
$lplot2 = new BarPlot($data2);
$lplot2->SetFillColor("blue");
$lplot2->SetLegend("Unique Visitors");
$gbplot = new GroupBarPlot(array($lplot,$lplot2));
$lplot->SetFillColor( "#BBCCFF");
$lplot->value->SetFormat('%01d');
$lplot->value->SetFont(FF_VERA,FS_NORMAL, 6);
$lplot2->value->SetFormat('%01d');
$lplot2->value->SetFont(FF_VERA,FS_NORMAL, 6);
$graph->xaxis->SetTickLabels($xdata);
//$graph->yaxis->title->Set("Monthly Pageviews");
$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('M');
$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(MONTHADJ_1);
$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);
$graph->legend->SetLayout(LEGEND_HOR);
$graph->legend->Pos(0.05,0.02, "left","top");
$graph->legend->SetFillColor("#FFFFFF@0.5");
$graph->legend->SetFont(FF_VERA,FS_NORMAL, 7.5);
$graph->legend->SetMarkAbsSize(6);
$graph->title->Set($text);
$graph->subtitle->Set($subtitle);
#list($tickPositions, $minTickPositions) = DateScaleUtils::GetTicks($xdata);
$graph->ygrid->SetFill(true,'#EFEFEF@0.5','#BBCCFF@0.5');
$graph->SetMarginColor("#ffffff");
$graph->xgrid->Show(true, false);
|