* @package Mammut\Chart */ class LineChart extends AbstractCoordinateChart implements iStackableChart { use Stackable; public function __construct() { $this->background = new Color(255, 255, 255); } public function render(iRenderer $renderer) { $renderer->start($this->width, $this->height, $this->background, iRenderer::HINT_LINE); $this->drawGrid($renderer, 10, 10, $this->width-15, $this->height-15); } // public function createImage($type = 'png') { // $image = imagecreatetruecolor($this->width, $this->height); // $bgColor = imagecolorexact($image, $this->background[0], $this->background[1], $this->background[2]); // $maxValueText = (string) $this->maxValue; // $numberSize = strlen($maxValueText) * imagefontwidth(1) + 5; // imagefilledrectangle($image, 0, 0, imagesx($image), imagesy($image), $bgColor); // $lineColor = imagecolorexact($image, 0, 0, 0); // $realWidth = $this->width - $numberSize; // $barWidth = $realWidth / count($this->datalines[0]); // foreach($this->datalines as $key=>$line) { // $x = $numberSize; // $realHeight = $this->height - 20; // $lastX = $numberSize; // $lastY = null; // $barColor = imagecolorexact($image, $this->lineColor[$key][0], $this->lineColor[$key][1], $this->lineColor[$key][2]); // foreach($line as $value) { // if(!is_null($value)) { // $realValue = round(($value / $this->maxValue) * $realHeight); // if(!is_null($lastY)) // imageline($image, $lastX, $lastY, $x, imagesy($image) - 20 - $realValue, $barColor); // $lastX = $x; // $lastY = imagesy($image) - 20 - $realValue; // } // else { // $lastX = $x; // $lastY = null; // } // $x += $barWidth; // } // } // /* imageline ($image, 16, 2, 20, 2, $lineColor); // imageline ($image, 16, imagesy($image)-20 - ($realHeight/2), 20, imagesy($image)-20 - ($realHeight/2), $lineColor); // imageline ($image, 20, 2, 20, imagesy($image)-20, $lineColor); // imageline ($image, imagesx($image), imagesy($image)-20, 16, imagesy($image)-20, $lineColor); // imagestring($image, 1, 1,0, $this->maxValue, $lineColor); // imagestring($image, 1, 1, imagesy($image)-23 - ($realHeight/2), round($this->maxValue/2), $lineColor); // imagestring($image, 1, 1, imagesy($image)-23, "0" , $lineColor); // */ // $this->drawGrid($image, 0, 0, imagesx($image), imagesy($image), $numberSize, 20); // ob_start(); // imagepng($image); // return ob_get_clean(); // } }