JpGraph: Beispiel: LinePlot: Statistik der Besucher, die von google kamen
<?PHP $monate = array("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"); foreach ($monate as $monat) $liste[$monat] = array(); /* * access_log wurde vorher mit * "grep '/2008:' access_log" auf das Jahr 2008 reduziert */ $handle = fopen("access_log", "r"); while (!feof($handle)) { $zeile = fgets($handle, 4096); $monat = explode("/", $zeile); $monat = $monat[1]; if ($p = (strstr($zeile, "google"))) { if ($p = (strstr($p, "?"))) { $p = substr($p, 1); if ($q = explode("&", $p)) { foreach ($q as $t) { if (substr($t, 0, 2) == "q=") { $t2 = explode("\"", $t); $liste[$monat][] = ($t2[0]) ? $t2[0] : $t; } } } } } } fclose ($handle); foreach ($liste as $monat => $b) { $gesamt[] = count($b); $unterschiedlich[] = count(array_unique($b)); $legende[] = $monat; $differenz[] = 0; $diff_values[] = $differenz[] = (count($b) - count(array_unique($b))); } $graph = new Graph(600, 300, "auto"); $graph->img->SetMargin(40, 20, 40, 75); $graph->SetScale("textlin"); $graph->SetMarginColor("#EBEBEB"); $graph->title->Set("Besucher von Google"); $graph->title->SetFont(FF_VERDANA, FS_BOLD, 9); $graph->title->SetMargin(8); $graph->title->SetColor("black"); $lineplot1 = new LinePlot($gesamt); $lineplot2 = new LinePlot($unterschiedlich); $lineplot3 = new LinePlot($diff_values); $errplot = new ErrorPlot($differenz); $lineplot1->SetFillColor("blue@0.6"); $lineplot1->SetColor("blue"); $lineplot1->SetWeight(1); $lineplot1->mark->SetType(MARK_FILLEDCIRCLE); $lineplot1->mark->SetFillColor("blue"); $lineplot1->mark->SetWidth(3); $lineplot1->value->Show(); $lineplot1->value->SetFont(FF_FONT0, FS_BOLD); $lineplot1->value->SetColor("black"); $lineplot1->value->SetFormat("%d"); $lineplot1->SetCenter(); $lineplot2->SetFillColor("red@0.6"); $lineplot2->SetColor("red"); $lineplot2->SetWeight(1); $lineplot2->mark->SetType(MARK_FILLEDCIRCLE); $lineplot2->mark->SetFillColor("red"); $lineplot2->mark->SetWidth(3); $lineplot2->SetCenter(); $lineplot3->SetWeight(0); $lineplot3->value->Show(); $lineplot3->value->SetFont(FF_FONT0, FS_BOLD); $lineplot3->value->SetColor("black"); $lineplot3->value->SetFormat("%d"); $lineplot3->SetCenter(); $errplot->SetColor("gray"); $errplot->SetWeight(1); $errplot->SetCenter(); $graph->Add($lineplot1); $graph->Add($lineplot2); $graph->Add($lineplot3); $graph->Add($errplot); $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->xaxis->SetTickLabels($legende); $graph->xaxis->HideTicks(true, true); $graph->yaxis->scale->SetGrace(15); $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); $lineplot1->SetLegend("unterschiedliche Besucher"); $lineplot2->SetLegend("unterschiedliche Suchbegriffe"); $errplot->SetLegend("gleiche Suchbegriffe"); $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->Stroke("include/tmp/jpgraph/JpGraph_GoogleBesucher.png"); ?>