JpGraph: Beispiel: ScatterPlot: Statistik über die Abweichung der Besucher nach Tagen
<?PHP /* * Suchmaschinen sind inbegriffen. */ $Monat = "Nov/2008"; $Anzahl = date("t", strtotime("01. ".(str_replace("/", " ", $Monat)))); $WochenTage = array("So", "Mo", "Di", "Mi", "Do", "Fr", "Sa"); for ($z = 1; $z <= $Anzahl; $z++) { $aBesucher[] = 0; $xAchse[] = $z; } $handle = fopen("access_log", "r"); while (!feof($handle)) { $zeile = fgets($handle, 4096); $gURL = explode("\"", $zeile); if (strstr($gURL[1], "?")) { if (strstr($gURL[0], $Monat)) { $p = explode(" ", $zeile); $ts = strtotime((substr($p[3], 8, 4))."-" .(date("m", strtotime("01. ".(str_replace("/", " ", $Monat))))) ."-{$p[3][1]}{$p[3][2]} ".(substr($p[3], 13, 8))); $Besucher[$p[0]][0] = $ts; if ( (!($Besucher[$p[0]][1])) || (($oBrowser <> $fBrowser) && ($p[0] == $oClient)) || (($Besucher[$p[0]][1] - $Besucher[$p[0]][0]) > 86400) ) { $Besucher[$p[0]][2][] = array($ts, 1); } if ($ts > $Besucher[$p[0]][1]) $Besucher[$p[0]][1] = $ts; $oClient = $p[0]; } } } fclose ($handle); foreach ($Besucher as $Anzahl) { foreach ($Anzahl[2] as $b) { $aBesucher[((int) date("d", $b[0]) - 1)]++; } } foreach ($aBesucher as $Tag => $Anzahl) { $ts = strtotime(($Tag)." ".(str_replace("/", " ", $Monat))); $legende[] = $WochenTage[date("w", $ts)]."\n".date("d", $ts)."."; } $ts += 86400; $legende[] = $WochenTage[date("w", $ts)]."\n".date("d", $ts)."."; $gesamt = array_sum($aBesucher); $durchschnitt = round($gesamt / count($aBesucher), 2); foreach ($aBesucher as $Tag => $Anzahl) $aBesucher[$Tag] = $Anzahl - $durchschnitt; $graph = new Graph(600, 300, "auto"); $graph->SetScale("linlin"); $graph->title->Set("Abweichung der Besucher nach Tagen (November)"); $graph->title->SetFont(FF_VERDANA, FS_BOLD, 9); $graph->title->SetMargin(8); $graph->title->SetColor("black"); $graph->img->SetMargin(40, 20, 40, 75); $graph->SetMarginColor("#EBEBEB"); $graph->xaxis->SetTickLabels($legende); $graph->xaxis->HideFirstTickLabel(); $graph->xaxis->HideLastTickLabel(); $graph->xaxis->SetPos("min"); $line1 = new PlotLine(HORIZONTAL, 0, "#0D6D00@0.5", 1); $splot1 = new ScatterPlot($aBesucher, $xAchse); $splot1->SetImpuls(); $splot1->SetColor("white@0.7"); $splot1->SetWeight(1); $splot1->mark->SetFillColor("red"); $splot1->mark->SetWidth(3); $lineplot1 = new LinePlot(array_merge(array(NULL), $aBesucher)); $lineplot1->SetFillColor("red@0.9"); $lineplot1->SetColor("red@0.6"); $lineplot1->SetWeight(1); $lineplot1->value->Show(); $lineplot1->value->SetFormat("%01.1f"); $lineplot1->value->SetFont(FF_FONT0, FS_BOLD); $lineplot1->value->SetColor("black"); $graph->xaxis->SetFont(FF_VERDANA, FS_BOLD, 7); $graph->yaxis->SetFont(FF_VERDANA, FS_BOLD, 7); $graph->yaxis->SetLabelMargin(12); $graph->xaxis->SetLabelMargin(12); $graph->yaxis->HideZeroLabel(); $graph->yaxis->scale->SetGrace(15, 15); $graph->xaxis->scale->SetGrace(0, 0); $graph->xgrid->Show(false, false); $graph->ygrid->Show(true, false); $graph->ygrid->SetColor("lightblue"); $graph->ygrid->SetFill(true, "#EFEFEF@0.6", "#BBCCFF@0.6"); $graph->ygrid->SetLineStyle("dashed"); $graph->ygrid->SetWeight(1); $splot1->SetLegend("Abweichung zum Durchschnitt"); $line1->SetLegend("durchschnittliche Besuche pro Tag ({$durchschnitt})"); $graph->legend->Pos(0.5, 0.97, "center", "bottom"); $graph->legend->SetLayout(LEGEND_HOR); $graph->legend->SetColor("darkblue"); $graph->legend->SetFont(FF_VERDANA, FS_BOLD, 7); $graph->legend->SetFillColor("white"); $graph->legend->SetShadow(FALSE); $graph->AddLine($line1); $graph->Add($lineplot1); $graph->Add($splot1); $graph->Stroke("include/tmp/jpgraph/JpGraph_AbweichungBesucher.png"); ?>