- if (strlen($this->x[$i]) > strlen($this->biggest_x))
- $this->biggest_x = $this->x[$i];
- if ($this->y[$i] > $this->biggest_y)
- $this->biggest_y = number_format(round($this->y[$i], 1), 1, ".", "");
- if ($this->graphic_2_exists)
- {
- if (isset($this->z[$i]) && $this->z[$i] > $this->biggest_y)
- $this->biggest_y = number_format(round($this->z[$i], 1), 1, ".", "");
- }
- }
-
- if (($this->graphic_2_exists == true) && ((!empty($this->graphic_1)) || (!empty($this->graphic_2))))
- {
- $this->legend_exists = true;
- }
-
- $this->sum_total = array_sum($this->y);
- if ($this->sum_total == 0)
- $this->sum_total = 1;
- $this->space_between_bars += ($this->graphic_2_exists == true) ? 10 : 0;
-
- $this->calculate_higher_value();
- $this->calculate_width();
- $this->calculate_height();
-
- $this->create_graphic($save, $border);
- }
-
- function create_graphic($save="", $border=false)
- {
- $size = 3;
- $this->img = imagecreatetruecolor($this->width, $this->height);
-
- $this->load_color_palette();
-
- // Fill background
- imagefill($this->img, 0, 0, $this->color['background']);
-
- // Draw title
- if (!empty($this->title))
- {
- $center = ($this->width / 2) - ($this->string_width($this->title, $this->tsize) / 2);
- $this->_imagestring($this->img, $this->tsize, $center, 10, $this->title, $this->color['title']);
- }
-
-
- // Draw axis and background lines for "vertical bars", "dots" and "lines"
- if (preg_match("/^(1|3|4)$/", $this->type))
- {
- if ($this->legend_exists == true)
- {
- $this->draw_legend();
- }
-
- $higher_value_y = $this->graphic_area_y1 + (0.1 * $this->graphic_area_height);
- $higher_value_size = 0.9 * $this->graphic_area_height;
-
- $less = 7 * strlen($this->higher_value_str);
-
- imageline($this->img, $this->graphic_area_x1, $higher_value_y, $this->graphic_area_x2, $higher_value_y, $this->color['bg_lines']);
- $this->_imagestring($this->img, $this->size, ($this->graphic_area_x1-$less-7), ($higher_value_y-7), $this->higher_value_str, $this->color['axis_values']);
-
- for ($i = 1; $i < 10; $i++)
- {
- $dec_y = $i * ($higher_value_size / 10);
- $x1 = $this->graphic_area_x1;
- $y1 = $this->graphic_area_y2 - $dec_y;
- $x2 = $this->graphic_area_x2;
- $y2 = $this->graphic_area_y2 - $dec_y;
-
- imageline($this->img, $x1, $y1, $x2, $y2, $this->color['bg_lines']);
- if ($i % 2 == 0)
- {
- $value = $this->number_formated($this->higher_value * $i / 10, $this->dec1);
- $len1 = strlen($this->higher_value_str);
- $len2 = strlen($value);
- if ($len2 < $len1)
- $len2 += ($len1-$len2-1);
- $less = 7 * $len2;
- $this->_imagestring($this->img, $this->size, ($x1-$less-7), ($y2-7), $value, $this->color['axis_values']);
- }
- }
-
- // Axis X
- $this->_imagestring($this->img, $this->size, $this->graphic_area_x2+40, $this->graphic_area_y2+3, $this->axis_x, $this->color['title']);
- imageline($this->img, $this->graphic_area_x1, $this->graphic_area_y2, $this->graphic_area_x2, $this->graphic_area_y2, $this->color['axis_line']);
- // Axis Y
- $this->_imagestring($this->img, $this->size, 20, $this->graphic_area_y1-20, $this->axis_y, $this->color['title']);
- imageline($this->img, $this->graphic_area_x1, $this->graphic_area_y1, $this->graphic_area_x1, $this->graphic_area_y2, $this->color['axis_line']);
- }
-
-
- // Draw axis and background lines for "horizontal bars"
- else if ($this->type == 2)
- {
- if ($this->legend_exists == true)
- {
- $this->draw_legend();
- }
-
- $higher_value_x = $this->graphic_area_x2 - (0.2 * $this->graphic_area_width);
- $higher_value_size = 0.8 * $this->graphic_area_width;
-
- imageline($this->img, ($this->graphic_area_x1+$higher_value_size), $this->graphic_area_y1, ($this->graphic_area_x1+$higher_value_size), $this->graphic_area_y2, $this->color['bg_lines']);
- $this->_imagestring($this->img, $this->size, (($this->graphic_area_x1+$higher_value_size) - ($this->string_width($this->higher_value, $this->size)/2)), ($this->graphic_area_y2+2), $this->higher_value_str, $this->color['axis_values']);
-
- for ($i = 1, $alt = 15; $i < 10; $i++)
- {
- $dec_x = number_format(round($i * ($higher_value_size / 10), 1), 1, ".", "");
-
- imageline($this->img, ($this->graphic_area_x1+$dec_x), $this->graphic_area_y1, ($this->graphic_area_x1+$dec_x), $this->graphic_area_y2, $this->color['bg_lines']);
- if ($i % 2 == 0)
- {
- $alt = (strlen($this->biggest_y) > 4 && $alt != 15) ? 15 : 2;
- $value = $this->number_formated($this->higher_value * $i / 10, $this->dec1);
- $this->_imagestring($this->img, $this->size, (($this->graphic_area_x1+$dec_x) - ($this->string_width($this->higher_value, $this->size)/2)), ($this->graphic_area_y2), $value, $this->color['axis_values'], $alt);
- }
- }
-
- // Axis X
- $this->_imagestring($this->img, $this->size, ($this->graphic_area_x2+10), ($this->graphic_area_y2+3), $this->axis_y, $this->color['title']);
- imageline($this->img, $this->graphic_area_x1, $this->graphic_area_y2, $this->graphic_area_x2, $this->graphic_area_y2, $this->color['axis_line']);
- // Axis Y
- $this->_imagestring($this->img, $this->size, 20, ($this->graphic_area_y1-20), $this->axis_x, $this->color['title']);
- imageline($this->img, $this->graphic_area_x1, $this->graphic_area_y1, $this->graphic_area_x1, $this->graphic_area_y2, $this->color['axis_line']);
- }
-
-
- // Draw legend box for "pie" or "donut"
- else if (preg_match("/^(5|6)$/", $this->type))
- {
- $this->draw_legend();
- }
-
-
-
- /**
- * Draw graphic: VERTICAL BARS
- */
- if ($this->type == 1)
- {
- $num = 1;
- $x = $this->graphic_area_x1 + 20;
-
- foreach ($this->x as $i => $parameter)
- {
- if (isset($this->z[$i]))
- {
- $size = round($this->z[$i] * $higher_value_size / $this->higher_value);
- $x1 = $x + 10;
- $y1 = ($this->graphic_area_y2 - $size) + 1;
- $x2 = $x1 + 20;
- $y2 = $this->graphic_area_y2 - 1;
- imageline($this->img, ($x1+1), ($y1-1), $x2, ($y1-1), $this->color['bars_2_shadow']);
- imageline($this->img, ($x2+1), ($y1-1), ($x2+1), $y2, $this->color['bars_2_shadow']);
- imageline($this->img, ($x2+2), ($y1-1), ($x2+2), $y2, $this->color['bars_2_shadow']);
- imagefilledrectangle($this->img, $x1, $y1, $x2, $y2, $this->color['bars_2']);
- }
-
- $size = round($this->y[$i] * $higher_value_size / $this->higher_value);
- $alt = (($num % 2 == 0) && (strlen($this->biggest_x) > 5)) ? 15 : 2;
- $x1 = $x;
- $y1 = ($this->graphic_area_y2 - $size) + 1;
- $x2 = $x1 + 20;
- $y2 = $this->graphic_area_y2 - 1;
- $x += $this->space_between_bars;
- $num++;
-
- imageline($this->img, ($x1+1), ($y1-1), $x2, ($y1-1), $this->color['bars_shadow']);
- imageline($this->img, ($x2+1), ($y1-1), ($x2+1), $y2, $this->color['bars_shadow']);
- imageline($this->img, ($x2+2), ($y1-1), ($x2+2), $y2, $this->color['bars_shadow']);
- imagefilledrectangle($this->img, $x1, $y1, $x2, $y2, $this->color['bars']);
- $this->_imagestring($this->img, $this->size, $x1, ($y2+2), $parameter, $this->color['axis_values'], $alt);
- }
- }
-
-
- /**
- * Draw graphic: HORIZONTAL BARS
- */
- else if ($this->type == 2)
- {
- $y = 10;
-
- foreach ($this->x as $i => $parameter)
- {
- if (isset($this->z[$i]))
- {
- $size = round($this->z[$i] * $higher_value_size / $this->higher_value);
- $x1 = $this->graphic_area_x1 + 1;
- $y1 = $this->graphic_area_y1 + $y + 10;
- $x2 = $x1 + $size;
- $y2 = $y1 + 15;
- imageline($this->img, ($x1), ($y2+1), $x2, ($y2+1), $this->color['bars_2_shadow']);
- imageline($this->img, ($x1), ($y2+2), $x2, ($y2+2), $this->color['bars_2_shadow']);
- imageline($this->img, ($x2+1), ($y1+1), ($x2+1), ($y2+2), $this->color['bars_2_shadow']);
- imagefilledrectangle($this->img, $x1, $y1, $x2, $y2, $this->color['bars_2']);
- $this->_imagestring($this->img, $this->size, ($x2+7), ($y1+7), $this->number_formated($this->z[$i], $this->dec2), $this->color['bars_2_shadow']);
- }
-
- $size = round(($this->y[$i] / $this->higher_value) * $higher_value_size);
- $x1 = $this->graphic_area_x1 + 1;
- $y1 = $this->graphic_area_y1 + $y;
- $x2 = $x1 + $size;
- $y2 = $y1 + 15;
- $y += $this->space_between_bars;
-
- imageline($this->img, ($x1), ($y2+1), $x2, ($y2+1), $this->color['bars_shadow']);
- imageline($this->img, ($x1), ($y2+2), $x2, ($y2+2), $this->color['bars_shadow']);
- imageline($this->img, ($x2+1), ($y1+1), ($x2+1), ($y2+2), $this->color['bars_shadow']);
- imagefilledrectangle($this->img, $x1, $y1, $x2, $y2, $this->color['bars']);
- $this->_imagestring($this->img, $this->size, ($x2+7), ($y1+2), $this->number_formated($this->y[$i], $this->dec2), $this->color['bars_shadow']);
-
- $this->_imagestring($this->img, $this->size, 30, ($y1+2), $parameter, $this->color['axis_values']);
- }
- }
-
-
- /**
- * Draw graphic: DOTS or LINE
- */
- else if (preg_match("/^(3|4)$/", $this->type))
- {
-
- $x[0] = $this->graphic_area_x1+1;
-
- foreach ($this->x as $i => $parameter)
- {
- if ($this->graphic_2_exists == true)
- {
- $size = round($this->z[$i] * $higher_value_size / $this->higher_value);
- $z[$i] = $this->graphic_area_y2 - $size;
- }
-
- $alt = (($i % 2 == 0) && (strlen($this->biggest_x) > 5)) ? 15 : 2;
- $size = round($this->y[$i] * $higher_value_size / $this->higher_value);
- $y[$i] = $this->graphic_area_y2 - $size;
-
- if ($i != 0)
- {
- imageline($this->img, $x[$i], ($this->graphic_area_y1+10), $x[$i], ($this->graphic_area_y2-1), $this->color['bg_lines']);
- }
- $this->_imagestring($this->img, $this->size, $x[$i], ($this->graphic_area_y2+2), $parameter, $this->color['axis_values'], $alt);
-
- $x[$i+1] = $x[$i] + 40;
- }
-
- foreach ($x as $i => $value_x)
- {
- if ($this->graphic_2_exists == true)
- {
- if (isset($z[$i+1]))
- {
- // Draw lines
- if ($this->type == 4)
- {
- imageline($this->img, $x[$i], $z[$i], $x[$i+1], $z[$i+1], $this->color['line_2']);
- imageline($this->img, $x[$i], ($z[$i]+1), $x[$i+1], ($z[$i+1]+1), $this->color['line_2']);
- }
- imagefilledrectangle($this->img, $x[$i]-1, $z[$i]-1, $x[$i]+2, $z[$i]+2, $this->color['line_2']);
- }
- else
- { // Draw last dot
- imagefilledrectangle($this->img, $x[$i-1]-1, $z[$i-1]-1, $x[$i-1]+2, $z[$i-1]+2, $this->color['line_2']);
- }
- }