Example #1
0
 function generate_graph_image()
 {
     // Create the graph.
     // Set up Font Mapping Arrays
     $fontfamilies = array("Font 0" => FF_FONT0, "Font 1" => FF_FONT1, "Font 2" => FF_FONT2, "Font0" => FF_FONT0, "Font1" => FF_FONT1, "Font2" => FF_FONT2, "Arial" => FF_ARIAL, "Verdana" => FF_VERDANA, "Courier" => FF_COURIER, "Comic" => FF_COMIC, "Times" => FF_TIMES, "Georgia" => FF_GEORGIA, "Trebuchet" => FF_TREBUCHE, "advent_light" => advent_light, "Bedizen" => Bedizen, "Mukti_Narrow" => Mukti_Narrow, "calibri" => calibri, "Forgotte" => Forgotte, "GeosansLight" => GeosansLight, "MankSans" => MankSans, "pf_arma_five" => pf_arma_five, "Silkscreen" => Silkscreen, "verdana" => verdana, "Vera" => FF_VERA);
     $fontstyles = array("Normal" => FS_NORMAL, "Bold" => FS_BOLD, "Italic" => FS_ITALIC, "Bold+Italic" => FS_BOLDITALIC);
     $this->apply_defaults();
     if (!function_exists("imagecreatefromstring")) {
         handle_error("Graph Option Not Available. Requires GD2");
         return;
     }
     if ($this->plot[0]["type"] == "PIE" || $this->plot[0]["type"] == "PIE3D") {
         $graph = new PieGraph($this->width_actual, $this->height_actual, "auto");
         $graph->SetScale("textlin");
         $graph->img->SetMargin($this->marginleft_actual, $this->marginright_actual, $this->margintop_actual, $this->marginbottom_actual);
         $graph->SetMarginColor($this->margincolor_actual);
         $graph->img->SetAntiAliasing();
         $graph->SetColor($this->graphcolor_actual);
         $graph->SetShadow();
         $graph->xaxis->SetTitleMargin($this->marginbottom_actual - 45);
         $graph->yaxis->SetTitleMargin($this->marginleft_actual - 25);
     } else {
         $graph = new Graph($this->width_actual, $this->height_actual, "auto");
         $graph->SetScale("textlin");
         $graph->img->SetMargin($this->marginleft_actual, $this->marginright_actual, $this->margintop_actual, $this->marginbottom_actual);
         $graph->SetMarginColor($this->margincolor_actual);
         $graph->img->SetAntiAliasing();
         $graph->SetColor($this->graphcolor_actual);
         $graph->SetShadow();
         $graph->xaxis->SetTitleMargin($this->marginbottom_actual - 45);
         $graph->yaxis->SetTitleMargin($this->marginleft_actual - 25);
     }
     $lplot = array();
     $lplotct = 0;
     foreach ($this->plot as $k => $v) {
         switch ($v["type"]) {
             case "PIE":
                 $lplot[$lplotct] = new PiePlot($v["data"]);
                 $lplot[$lplotct]->SetColor($v["linecolor"]);
                 foreach ($xlabels as $k => $v) {
                     $xlabels[$k] = $v . "\n %.1f%%";
                 }
                 $lplot[$lplotct]->SetLabels($xlabels, 1.0);
                 $graph->Add($lplot[$lplotct]);
                 break;
             case "PIE3D":
                 $lplot[$lplotct] = new PiePlot3D($v["data"]);
                 $lplot[$lplotct]->SetColor($v["linecolor"]);
                 foreach ($xlabels as $k => $v) {
                     $xlabels[$k] = $v . "\n %.1f%%";
                 }
                 $lplot[$lplotct]->SetLabels($xlabels, 1.0);
                 $graph->Add($lplot[$lplotct]);
                 break;
             case "STACKEDBAR":
             case "BAR":
                 $lplot[$lplotct] = new BarPlot($v["data"]);
                 $lplot[$lplotct]->SetColor($v["linecolor"]);
                 $lplot[$lplotct]->SetWidth(0.8);
                 //$lplot[$lplotct]->SetWeight(5);
                 if ($v["fillcolor"]) {
                     $lplot[$lplotct]->SetFillColor($v["fillcolor"]);
                 }
                 if ($v["legend"]) {
                     $lplot[$lplotct]->SetLegend($v["legend"]);
                 }
                 $graph->Add($lplot[$lplotct]);
                 break;
             case "LINE":
             default:
                 if (count($v["data"]) == 1) {
                     $v["data"][] = 0;
                 }
                 $lplot[$lplotct] = new LinePlot($v["data"]);
                 $lplot[$lplotct]->SetColor($v["linecolor"]);
                 //$lplot[$lplotct]->SetWeight(5);
                 if ($v["fillcolor"]) {
                     $lplot[$lplotct]->SetFillColor($v["fillcolor"]);
                 }
                 if ($v["legend"]) {
                     $lplot[$lplotct]->SetLegend($v["legend"]);
                 }
                 $graph->Add($lplot[$lplotct]);
                 break;
         }
         $lplotct++;
     }
     $graph->title->Set($this->title_actual);
     $graph->xaxis->title->Set($this->xtitle_actual);
     $graph->yaxis->title->Set($this->ytitle_actual);
     $graph->xgrid->SetColor($this->xgridcolor_actual);
     $graph->ygrid->SetColor($this->ygridcolor_actual);
     switch ($this->xgriddisplay_actual) {
         case "all":
             $graph->xgrid->Show(true, true);
             break;
         case "major":
             $graph->xgrid->Show(true, false);
             break;
         case "minor":
             $graph->xgrid->Show(false, true);
             break;
         case "none":
         default:
             $graph->xgrid->Show(false, false);
             break;
     }
     switch ($this->ygriddisplay_actual) {
         case "all":
             $graph->ygrid->Show(true, true);
             break;
         case "major":
             $graph->ygrid->Show(true, false);
             break;
         case "minor":
             $graph->ygrid->Show(false, true);
             break;
         case "none":
         default:
             $graph->ygrid->Show(false, false);
             break;
     }
     $graph->title->SetFont($fontfamilies[$this->titlefont_actual], $fontstyles[$this->titlefontstyle_actual], $this->titlefontsize_actual);
     $graph->title->SetColor($this->titlecolor_actual);
     $graph->xaxis->SetFont($fontfamilies[$this->xaxisfont_actual], $fontstyles[$this->xaxisfontstyle_actual], $this->xaxisfontsize_actual);
     $graph->xaxis->SetColor($this->xaxiscolor_actual, $this->xaxisfontcolor_actual);
     $graph->yaxis->SetFont($fontfamilies[$this->yaxisfont_actual], $fontstyles[$this->yaxisfontstyle_actual], $this->yaxisfontsize_actual);
     $graph->yaxis->SetColor($this->yaxiscolor_actual, $this->yaxisfontcolor_actual);
     $graph->xaxis->title->SetFont($fontfamilies[$this->xtitlefont_actual], $fontstyles[$this->xtitlefontstyle_actual], $this->xtitlefontsize_actual);
     $graph->xaxis->title->SetColor($this->xtitlecolor_actual);
     $graph->yaxis->title->SetFont($fontfamilies[$this->ytitlefont_actual], $fontstyles[$this->ytitlefontstyle_actual], $this->ytitlefontsize_actual);
     $graph->yaxis->title->SetColor($this->ytitlecolor_actual);
     $graph->xaxis->SetLabelAngle(90);
     $graph->xaxis->SetLabelMargin(5);
     $graph->yaxis->SetLabelMargin(5);
     $graph->xaxis->SetTickLabels($this->xlabels);
     $graph->xaxis->SetTextLabelInterval($this->xticklabelinterval_actual);
     $graph->yaxis->SetTextLabelInterval($this->yticklabelinterval_actual);
     $graph->xaxis->SetTextTickInterval($this->xtickinterval_actual);
     $graph->yaxis->SetTextTickInterval($this->ytickinterval_actual);
     $graph->SetFrame(true, 'darkblue', 2);
     $graph->SetFrameBevel(2, true, 'black');
     if ($this->gridpos_actual == "front") {
         $graph->SetGridDepth(DEPTH_FRONT);
     }
     // Display the graph
     $handle = $graph->Stroke(_IMG_HANDLER);
     return $handle;
 }
Example #2
0
        break;
    case "none":
    default:
        $graph->ygrid->Show(false, false);
        break;
}
$graph->title->SetFont($fontfamilies[$titlefont], $fontstyles[$titlefontstyle], $titlefontsize);
$graph->title->SetColor($titlecolor);
$graph->xaxis->SetFont($fontfamilies[$xaxisfont], $fontstyles[$xaxisfontstyle], $xaxisfontsize);
$graph->xaxis->SetColor($xaxiscolor, $xaxisfontcolor);
$graph->yaxis->SetFont($fontfamilies[$yaxisfont], $fontstyles[$yaxisfontstyle], $yaxisfontsize);
$graph->yaxis->SetColor($yaxiscolor, $yaxisfontcolor);
$graph->xaxis->title->SetFont($fontfamilies[$xtitlefont], $fontstyles[$xtitlefontstyle], $xtitlefontsize);
$graph->xaxis->title->SetColor($xtitlecolor);
$graph->yaxis->title->SetFont($fontfamilies[$ytitlefont], $fontstyles[$ytitlefontstyle], $ytitlefontsize);
$graph->yaxis->title->SetColor($ytitlecolor);
$graph->xaxis->SetLabelAngle(90);
$graph->xaxis->SetLabelMargin(15);
$graph->yaxis->SetLabelMargin(15);
$graph->xaxis->SetTickLabels($xlabels);
$graph->xaxis->SetTextLabelInterval($xticklabint);
$graph->yaxis->SetTextLabelInterval($yticklabint);
$graph->xaxis->SetTextTickInterval($xtickinterval);
$graph->yaxis->SetTextTickInterval($ytickinterval);
$graph->SetFrame(true, 'darkblue', 2);
$graph->SetFrameBevel(2, true, 'black');
if ($gridpos == "front") {
    $graph->SetGridDepth(DEPTH_FRONT);
}
// Display the graph
$graph->Stroke();