Beispiel #1
0
 public function plot($file)
 {
     $yaxis = new Graph_DefaultAxis($this->getMinData(), $this->getMaxData());
     $img = ImageCreate($this->getWidth(), $this->getHeight());
     $background = ImageColorAllocate($img, 255, 255, 255);
     $axiscolor = ImageColorAllocate($img, 0, 0, 0);
     // Y-Axis
     $posYaxis = 0;
     $lastYpixel_label = null;
     $lastYpixel_line = null;
     while ($yaxis->getLabelPosition($posYaxis) < 1 && $posYaxis < 30) {
         $labelPosition = $yaxis->getLabelPosition($posYaxis);
         $label = $yaxis->getLabel($labelPosition);
         $yPixel = $labelPosition * $this->getPlotHeight();
         $y = $this->getPlotYOffset() + ($this->getPlotHeight() - $yPixel);
         $preXpixel = ImageFontWidth($this->getAxisFont()) * strlen($label);
         $preYpixel = ImageFontHeight($this->getAxisFont()) / 2;
         $postYpixel = ImageFontHeight($this->getAxisFont()) / 2;
         if ($lastYpixel_label == null || $lastYpixel_label + 20 < $yPixel - $preYpixel) {
             ImageString($img, $this->getAxisFont(), $this->getPlotYAxisPosition() - $preXpixel, $y - $preYpixel, iconv("UTF8", "ISO-8859-1", $label), $axiscolor);
             $lastYpixel_label = $yPixel + $postYpixel;
         }
         if ($lastYpixel_line == null || $lastYpixel_line + 20 < $yPixel) {
             ImageLine($img, $this->getPlotXOffset(), $y, $this->getPlotXOffset() + $this->getPlotWidth(), $y, $axiscolor);
             $lastYpixel_line = $yPixel;
         }
         $posYaxis++;
     }
     // Data
     $lastXpixel_label = null;
     $y_null = $this->getPlotHeight() - $this->getPlotHeight() * $yaxis->getPosition(0);
     for ($i = 0; $i < $this->getDataCount(); $i++) {
         $dataColor = $this->getDataColor($i)->gdAllocate($img);
         $x = $this->getDataXPosition($i);
         $y = $this->getPlotHeight() - $this->getPlotHeight() * $yaxis->getPosition($this->getDataValue($i));
         for ($x_bar = $x - floor($this->getBarWidth() / 2); $x_bar <= $x + $this->getBarWidth() / 2; $x_bar++) {
             ImageLine($img, $x_bar, $y, $x_bar, $y_null, $dataColor);
         }
         // Draw Axis
         $label = $this->getDataLegend($i);
         $preXpixel = ImageFontWidth($this->getAxisFont()) * strlen($label) / 2;
         $postXpixel = ImageFontWidth($this->getAxisFont()) * strlen($label) / 2;
         if ($lastXpixel_label == null || $lastXpixel_label + 20 < $x - $preXpixel) {
             ImageString($img, $this->getAxisFont(), $x - $preXpixel, $this->getPlotXAxisPosition(), iconv("UTF8", "ISO-8859-1", $label), $axiscolor);
             $lastXpixel_label = $x + $postXpixel;
         }
     }
     // Output
     if ($file != null) {
         $file->setMimeType("image/png");
         if (substr($file->getExportFilename(), 0, -4) != ".png") {
             $file->setExportFilename($file->getExportFilename() . ".png");
         }
         $file->save();
         ImagePNG($img, $file->getAbsoluteFileName());
     } else {
         header("Content-Type: image/png");
         ImagePNG($img);
     }
 }
Beispiel #2
0
 public function __construct($min, $max, $dateFormat, $timeMulti)
 {
     parent::__construct($min, $max, $timeMulti);
     $this->dateFormat = $dateFormat;
 }