JpGraph: Beispiel: PiePlotC: Statistik der Besucher nach Land bzw. Domain
<?PHP function gDomain($sDomain, &$vDomains) { $c = geoip_country_code_by_name($sDomain); if (in_array($c, $vDomains)) return (array_search($c, $vDomains)); return (count($vDomains) - 1); } /* * Die hier dargestellte Ermittlung der Domains spiegelt nicht die * tatsaechliche Verteilung der Domains der Besucher da, da mehrfache * Besuche gleicher IP-Adressen nicht beruecksichtig werden. */ $Domains = array("Deutschland", "Oesterreich", "Schweiz", "andere"); $vDomains = array("DE", "AT", "CH", "%"); for ($z = 0; $z < count($Domains); $z++) $aDomains[$z] = 0; $handle = fopen("access_log", "r"); while (!feof($handle)) { $zeile = fgets($handle, 4096); $iDomain = explode("\"", $zeile); if (strstr($iDomain[1], "?")) { $p = explode(" ", $zeile); if (!$bDomains[$p[0]]) $bDomains[$p[0]] = gDomain($p[0], $vDomains); } } fclose ($handle); foreach ($bDomains as $bDomain) $aDomains[$bDomain]++; $graph = new PieGraph(600, 300, "auto"); $graph->title->Set("Besucher nach deutschsprachigem Land bzw. Domain"); $graph->title->SetFont(FF_VERDANA,FS_BOLD, 9); $graph->title->SetMargin(8); $graph->title->SetColor("black"); $graph->SetColor("#EBEBEB"); $pplot1 = new PiePlotC($aDomains); $pplot1->SetSize(0.38); $pplot1->SetCenter(0.75, 0.50); $pplot1->SetLabelPos(0.75); $pplot1->SetLegends($Domains); $pplot1->midtitle->Set("prozentual"); $pplot1->midtitle->SetFont(FF_VERDANA, FS_BOLD, 10); $pplot1->SetMidColor("yellow@0.25"); $pplot1->SetMidSize(0.45); $pplot1->SetLabelType(PIE_VALUE_ADJPER); $pplot1->SetSliceColors(array("#2BA5D5@0.7", "#2CD538@0.7", "#D5D530@0.7", "#D52C2F@0.7")); $pplot1->SetGuideLines(false); $pplot1->ShowBorder(false, false); $pplot1->SetStartAngle(270); $pplot1->value->Show(); $pplot1->value->SetFormat("%d%%"); $pplot1->value->SetFont(FF_FONT1, FS_BOLD, 9); $pplot1->value->SetColor("black"); $pplot1->value->HideZero(); $pplot2 = new PiePlotC($aDomains); $pplot2->SetSize(0.38); $pplot2->SetCenter(0.25, 0.50); $pplot2->SetLabelPos(0.75); $pplot2->midtitle->Set("absolut"); $pplot2->midtitle->SetFont(FF_VERDANA, FS_BOLD, 10); $pplot2->SetMidColor("yellow@0.25"); $pplot2->SetMidSize(0.45); $pplot2->SetLabelType(PIE_VALUE_ABS); $pplot2->SetSliceColors(array("#2BA5D5@0.7", "#2CD538@0.7", "#D5D530@0.7", "#D52C2F@0.7")); $pplot2->SetGuideLines(false); $pplot2->ShowBorder(false, false); $pplot2->SetStartAngle(270); $pplot2->value->Show(); $pplot2->value->SetFormat("%d"); $pplot2->value->SetFont(FF_FONT1, FS_BOLD, 9); $pplot2->value->SetColor("black"); $pplot2->value->HideZero(); $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->Add($pplot1); $graph->Add($pplot2); $graph->Stroke("include/tmp/jpgraph/JpGraph_BesucherDomain.png"); ?>