function DrawGraph($file = "") { $this->graph_width = $this->graph_padding['left'] + count($this->data) * ($this->bar_width + $this->bar_padding * 2) + $this->graph_padding['right']; $this->axis_deepness = $this->bar_height; $this->im = imagecreatetruecolor($this->graph_width, $this->graph_height); $this->axis_frontgridlines = 0; $this->axis_xscalevisible = 0; $this->axis_positions = array($this->axis_positions[0], 0, 0, 0); CGraph::DrawGraph(); if ($this->axis_minY > 0) { $this->axis_minY = 0; } if ($this->axis_maxY < 0) { $this->axis_maxY = 0; } $this->__Draw_LeftBottom_Axis(); $p = 0; foreach ($this->data as $name => $value) { $p++; $this->__DrawBarText($p, $name); $this->__DrawBar($p, $value); } $this->__Draw_TopRight_Axis(); CGraph::DrawGraph2(); if (strlen($file)) { $ret = imagepng($this->im, $file); } else { header("Content-Type: image/png"); // thanks to Marcin G. :) imagepng($this->im); $ret = true; } imagedestroy($this->im); return $ret; }
/** * Graph::DrawGraph() * Draw all the graph: bg, axis, bars, text.. and output it * Optional file parameter turns output to file, and bool on success **/ function DrawGraph($file = "") { $this->im = imagecreatetruecolor($this->graph_width, $this->graph_height); CGraph::DrawGraph(); $this->__Draw_LeftBottom_Axis(); $arrki = array_keys($this->data); if (is_array($this->data[$arrki[0]])) { // more than 1 line if (!is_array($this->line_color)) { $this->line_color = array($this->line_color); } if (!is_array($this->line_bgcolor)) { $this->line_bgcolor = array($this->line_bgcolor); } for ($i = 0; $i < count($arrki); $i++) { $this->__AllocateColor("im_line_color", $this->line_color[$i], $this->graph_transparencylevel, $i); if ($this->axis_deepness > 0) { $this->__AllocateColor("im_line_bgcolor", $this->line_bgcolor[$i], $this->graph_transparencylevel, $i); } $arrkj = array_keys($this->data[$arrki[$i]]); for ($j = 1; $j < count($arrkj); $j++) { $this->__DrawLine(array($arrkj[$j - 1], $arrkj[$j], $this->data[$arrki[$i]][$arrkj[$j - 1]], $this->data[$arrki[$i]][$arrkj[$j]]), $this->im_line_color[$i], $this->im_line_bgcolor[$i]); } } } else { $this->__AllocateColor("im_line_color", $this->line_color, $this->graph_transparencylevel); $this->__AllocateColor("im_line_bgcolor", $this->line_bgcolor, $this->graph_transparencylevel); for ($i = 1; $i < count($arrki); $i++) { $this->__DrawLine(array($arrki[$i - 1], $arrki[$i], $this->data[$arrki[$i - 1]], $this->data[$arrki[$i]]), $this->im_line_color, $this->im_line_bgcolor); } } $this->__Draw_TopRight_Axis(); CGraph::DrawGraph2(); if (strlen($file)) { $ret = imagepng($this->im, $file); } else { header("Content-Type: image/png"); // thanks to Marcin G. :) imagepng($this->im); $ret = true; } imagedestroy($this->im); return $ret; }
function DrawGraph($file = "") { $this->im = imagecreatetruecolor($this->graph_width, $this->graph_height); $this->axis_positions = array(0, 0, 0, 0); $this->axis_xscalevisible = 0; $this->axis_yscalevisible = 0; $this->axis_gridlines = 0; CGraph::DrawGraph(); if ($this->pie_total == 0) { foreach ($this->data as $name => $value) { $this->pie_total += $value; } } // deepness for ($i = $this->pie_deepness; $i > 0; $i--) { $offset = 0; $p = 0; foreach ($this->data as $n => $value) { if (!$this->im_pie_deepnesscolor[$p]) { $this->__AllocateColor("im_pie_deepnesscolor", $this->pie_deepnesscolor[$p], 0, $p); } $from = round($this->pie_startoffset - $offset * 360 / $this->pie_total); $to = round($this->pie_startoffset - ($value + $offset) * 360 / $this->pie_total); if ($from < 0) { $from += 360; } if ($to < 0) { $to += 360; } imagefilledarc($this->im, round($this->graph_width / 2), round($this->graph_height / 2) + $i, $this->graph_areawidth, $this->graph_areaheight, $to, $from, $this->im_pie_deepnesscolor[$p], IMG_ARC_PIE); $offset += $value; $p++; } } $offset = 0; $p = 0; foreach ($this->data as $n => $value) { $this->__AllocateColor("im_pie_color", $this->pie_color[$p], 0, $p); $from = round($this->pie_startoffset - $offset * 360 / $this->pie_total); $to = round($this->pie_startoffset - ($value + $offset) * 360 / $this->pie_total); if ($from < 0) { $from += 360; } if ($to < 0) { $to += 360; } imagefilledarc($this->im, round($this->graph_width / 2), round($this->graph_height / 2), $this->graph_areawidth, $this->graph_areaheight, $to, $from, $this->im_pie_color[$p], IMG_ARC_PIE); $offset += $value; $p++; } CGraph::DrawGraph2(); if (strlen($file)) { $ret = imagepng($this->im, $file); } else { header("Content-Type: image/png"); // thanks to Marcin G. :) imagepng($this->im); $ret = true; } imagedestroy($this->im); return $ret; }