* @package Mammut\Chart */ class BarChart extends AbstractChart 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); $all = 0; foreach ($this->chartData as $element) $all += $element->payload; $start = 0; $div = ($this->height-5); $count = count($this->chartData); if ($this->isStacking()) { } else { $width = ($this->width/$count); $x = 1; foreach ($this->chartData as $element) { $delta = ($element->payload/$all)*$div; $renderer->drawRect($x+1, ($this->height-2)-$delta, $x+$width-1, ($this->height-2), $element->color, true); $x += $width; } } } // public function createImage($type = 'png') { // $image = imagecreatetruecolor($this->width, $this->height); // $bgColor = imagecolorexact($image, $this->background[0], $this->background[1], $this->background[2]); // imagefilledrectangle($image, 0, 0, imagesx($image), imagesy($image), $bgColor); // $maxValueText = (string) $this->maxValue; // $numberSize = strlen($maxValueText) * imagefontwidth(1) + 5; // $lineColor = imagecolorexact($image, 0, 0, 0); // $barColor = imagecolorexact($image, 200, 0, 0); // $realWidth = $this->width - 20; // $barWidth = $realWidth / count($this->datalines[0]); // $x = 20; // $realHeight = $this->height - 20; // $size = ($barWidth - 2) / count($this->datalines); // foreach($this->datalines as $key=>$line) { // $x = 20; // $realHeight = $this->height - 20; // $lastX = 20; // $lastY = $realHeight; // $barColor = imagecolorexact($image, $this->lineColor[$key][0], $this->lineColor[$key][1], $this->lineColor[$key][2]); // foreach($line as $value) { // $realValue = round(($value / $this->maxValue) * $realHeight); // imagefilledrectangle($image, $x + 2 + ($size * $key), imagesy($image) - 20, $x + 2 + ($size * $key) + $size - 1, imagesy($image) - 20 - $realValue, $barColor); // $x += $barWidth; // } // } // // imageline ($image, 20, 0, 20, imagesy($image)-20, $lineColor); // // imageline ($image, imagesx($image), imagesy($image)-20, 20, imagesy($image)-20, $lineColor); // $this->drawGrid($image, 0, 0, imagesx($image), imagesy($image), $numberSize, 20); // ob_start(); // imagepng($image); // return ob_get_clean(); // } }