JpGraph: Beispiel: AccBarPlot: Positionsseite in Google
geschrieben von Julian Hofmann am 26. Januar 2009 - zuletzt aktualisiert am 5. August 2013
<?PHP $monate = array("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"); foreach ($monate as $monat) { $liste[$monat] = array(); for ($r = 0; $r < 5; $r++) $ergebnis[$r][] = 0; } /* * 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)) { $query = NULL; $start = 1; foreach ($q as $t) { if (substr($t, 0, 6) == "start=") $start = (int) (substr($t, 6) / 10) + 1; if (substr($t, 0, 2) == "q=") { $t2 = explode("\"", $t); $query = ($t2[0]) ? $t2[0] : $t; } } if ($query) $liste[$monat][] = $start; } } } } fclose ($handle); $k = 0; foreach ($liste as $monat => $b) { foreach ($b as $val) if ($val == 1) $ergebnis[0][$k]++; elseif ($val < 4) $ergebnis[1][$k]++; elseif ($val < 11) $ergebnis[2][$k]++; elseif ($val < 51) $ergebnis[3][$k]++; else $ergebnis[4][$k]++; $gesamt[] = count($b); $legende[] = $monat; $k++; } $graph = new Graph(600, 300, "auto"); $graph->img->SetMargin(40, 20, 40, 30); $graph->SetScale("textlin"); $graph->SetMarginColor("#EBEBEB"); $graph->title->Set("Position nach Seite von Google"); $graph->title->SetFont(FF_VERDANA, FS_BOLD, 9); $graph->title->SetMargin(8); $graph->title->SetColor("black"); $bplot1 = new BarPlot($ergebnis[0]); $bplot1->SetFillColor("orange@0.4"); $bplot1->SetLegend("Seite 1"); $bplot1->SetValuePos("bottom"); $bplot1->value->Show(); $bplot1->value->SetFont(FF_FONT0, FS_BOLD); $bplot1->value->SetColor("black"); $bplot1->value->SetFormat("%d"); $bplot2 = new BarPlot($ergebnis[1]); $bplot2->SetFillColor("red@0.4"); $bplot2->SetLegend("Seite 2 und 3"); $bplot2->SetValuePos("bottom"); $bplot2->value->Show(); $bplot2->value->SetFont(FF_FONT0, FS_BOLD); $bplot2->value->SetColor("black"); $bplot2->value->SetFormat("%d"); $bplot3 = new BarPlot($ergebnis[2]); $bplot3->SetFillColor("green@0.4"); $bplot3->SetLegend("Seite 4 bis 10"); $bplot4 = new BarPlot($ergebnis[3]); $bplot4->SetFillColor("black@0.4"); $bplot4->SetLegend("Seite 11 bis 50"); $bplot5 = new BarPlot($ergebnis[4]); $bplot5->SetFillColor("blue@0.4"); $bplot5->SetLegend("Seite \374ber 50"); $gbplot1 = new AccBarPlot(array($bplot1, $bplot2, $bplot3, $bplot4, $bplot5)); $graph->Add($gbplot1); $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(20); $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); $graph->legend->Pos(0.885, 0.25, "center", "bottom"); $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_GooglePosition.png"); ?>