Page 1 of 1

Problem is Graph

Posted: Wed Feb 09, 2011 2:37 am
by webindia
hi
i want to show gdline graph in my report when i test in local ser it is working but in server it is not showing the graph.
my code follows

this is for graph

Code: Select all

if(!class_exists('GDGRAPH')){
define('GDGRAPH_VERSION','2.1.0');
class GDGraph{
	//Protected properties
	var $image;					//actual image
	var $width;					//width of whole image
	var $height;				//height of whole image
	var $line_color;			//color of surrounding lines
	var $line_thickness;		//thickness of surrounding lines
	var $title;					//title of graph
	
	var $bg_color;				//background color
	var $bg_trans;				//background transparency
	var $left_border;			//distance from left border
	var $right_border;			//distance from right border
	var $top_border;			//distance from top border
	var $bottom_border;			//distance from bottom border
	var $font_color;			//font color
	var $legend;				//if it's going to include a legend
	var $legend_border;			//if it's going to print a border legend
	var $legend_x;				//x position of legend
	var $legend_y;				//y position of legend



	
	/****************** Public methods *******************/

	//Constructor.
	//	Defaults:
	//		With legend
	//		With legend border
	//		No titles
	//		White solid (non-transparent) background
	//		Black lines
	//		Black font
	//		1 pixel thick lines.
	function GDGraph($w, $h, $t="",$sfooter, $bg_c_r=255, $bg_c_g=255, $bg_c_b=255, $l_c_r=0, $l_c_g=0, $l_c_b=0, $str_c_r=0, $str_c_g=0, $str_c_b=0, $l=true,$l_x=NULL,$l_y=NULL,$l_border=true,$trans_back=false, $l_thickness=2){
		$this->width = $w+0;
		$this->height = $h+0;
		
		if ($this->width <= 0 || $this->height <= 0){
			die("GDGraph Error: Width nor height can be smaller or equal to 0.");
		}
		
		//image margin
		$image_wmargin=100;
		$image_hmargin=50;
		$this->image = imagecreate($this->width + $image_wmargin, $this->height  + $image_hmargin);		
		$this->line_color = imagecolorallocate($this->image, ($l_c_r+0), ($l_c_g+0), ($l_c_b+0));
		$this->line_thickness = $l_thickness;
		$this->bg_color = imagecolorallocate($this->image, ($bg_c_r+0), ($bg_c_g+0), ($bg_c_b+0));
		$this->bg_trans = $trans_back;
		$this->font_color = imagecolorallocate($this->image, ($str_c_r+0), ($str_c_g+0), ($str_c_b+0));
		$this->title = $t."";
		$this->left_border = ceil($this->width * 0.05);
		$this->right_border = $this->width - $this->left_border;
		$this->top_border = ceil($this->height * 0.05);
		$this->bottom_border = $this->height - $this->top_border;

		$this->legend = ($l && true);
		$this->legend_border = ($l_border && true);
		$this->legend_x = $l_x;
		$this->legend_y = $l_y;
		
    	$this->Footer=$sfooter."";


		//Activate background color
		imagefill($this->image, 0 ,0, $this->bg_color);

		//Activate transparency
		if ($this->bg_trans){
			imagecolortransparent($this->image, $this->bg_color);
		}

		//Activating line thickness
		imagesetthickness($this->image, $this->line_thickness);
	}

	//Line Graph.
	//	Arrays format:
	//		Data Array:
	//			Name of line => (value in t1, value in t2, value in t3 ...)
	//		Color Array:
	//			Name of line => (red, green, blue)
	//		X Axis Labels Array:
	//			t1, t2, t3 ...
	//		Line Thickness Array:
	//			Name of line => thickness of line
	//	Defaults:
	//		Black, 1 pixel thick lines
	//		No labels
	//		No limits
	function line_graph($data, $color=Array(), $x_ls=Array(), $x_t="", $y_t="", $inc_dot=true, $l_t=Array(), $g_per=0, $x_rl=NULL,  $x_ru=NULL, $y_rl=NULL,  $y_ru=NULL){
		if((((!is_null($x_rl)) && (!is_null($x_ru))) && ($x_rl >= $x_ru)) || (((!is_null($y_rl)) && (!is_null($y_ru))) && ($y_rl >= $y_ru)))
			die("Lower ranges of either X or Y can't be greater or equal to their upper ranges.");

		//Acknowledging the line graph limits in the X axis
		//We start by the color array... this is the same thing we're going to do
		//with the t values of each line's data array
		if ((!is_null($x_rl)) && (!is_null($x_ru))){
			$x_ls = array_slice($x_ls,$x_rl,($x_ru-$x_rl+1));
		}else if(!is_null($x_rl)){
			$x_ls = array_slice($x_ls,$x_rl);
		}else if(!is_null($x_ru)){
			$x_ls = array_slice($x_ls,0,$x_ru+1);
		}

		//Now we do that with the data array
		if ((!is_null($x_rl)) && (!is_null($x_ru))){
			foreach($data as $prod => $sub_data)
					$data[$prod] = array_slice($sub_data,$x_rl,($x_ru-$x_rl+1));
		}else if(!is_null($x_rl)){
			foreach($data as $prod => $sub_data)
				$data[$prod] = array_slice($sub_data,$x_rl);
		}else if(!is_null($x_ru)){
			foreach($data as $prod => $sub_data)
				$data[$prod] = array_slice($sub_data,0,$x_ru+1);
		}

		//Obtain all the specs of the data from the array,
		//including the Y axis length in data value without extra bottom nor top
		$specs = $this->_get_specs($data,"line");

		//Acknowledging the line graph limits in the Y axis
		//this is done by overriding the max_value and min_value specs
		if(!is_null($y_ru))
			$specs['max_value'] = $y_ru;

		if(!is_null($y_rl))
			$specs['min_value'] = $y_rl;
		
		if($specs['max_value'] < $specs['min_value'])
			die("Lower ranges of either X or Y can't be greater or equal to their upper ranges.");

		//This next section is
		//guaranteeing a completely scalable graph independently if graphing .001 or 1000
		$y_axis_slength = 0;
		$all_down = false;
		$all_up = false;
		if (($specs['max_value'] == 0) && ($specs['min_value'] == 0)){
			$y_axis_length = 10;
		}else{
			// the max % y axis length is 100
			$y_axis_length = $specs["max_value"]-$specs['min_value'];

			//Getting the exponent to expand the y-axis length to cover
			$y_dig = 0;
			$y_division_value = $y_axis_length;
			if ($y_axis_length < 1){
				while ($y_division_value < 1){
					$y_dig++;
					$y_division_value *= 10;
				}
			}else {
				$y_dig = 1;
				while ($y_division_value >= 10){
					$y_dig--;
					$y_division_value /= 10;
				}
			}

			$y_dec = 0;
			if((!is_null($y_rl)) || (!is_null($y_ru))){
				//if some range was imposed, we make sure it's exact
				$y_t_min = abs($specs["min_value"])."";
				$y_t_array = explode(".",$y_t_min,2);
				if(array_key_exists(1, $y_t_array))
					$y_t_min = $y_t_array[1]."";
				else
					$y_t_min = "";

				$y_t_max = abs($specs["max_value"])."";
				$y_t_array = explode(".",$y_t_max,2);
				if(array_key_exists(1, $y_t_array))
					$y_t_max = $y_t_array[1]."";
				else
					$y_t_max = "";;

				$y_dec = max(strlen($y_t_max),strlen($y_t_min));
			}

			$y_dig = pow(10,$y_dig+$y_dec);

			$y_axis_length = ceil(($specs["max_value"]*$y_dig)-($specs['min_value']*$y_dig))/$y_dig;
			$y_axis_slength = $y_axis_length-(ceil($specs['max_value']*$y_dig)/$y_dig);

			//After this, if no range was imposed:
			//If the numerical length of the y_axis is 3,124, y_axis_length is 3,200
			//if it's 0.002292, y_axis_length is 0.0023, which will become the real
			//numerical length of they y-axis

			//Setting some flags
			if ($specs['max_value'] > 0){
				if ($specs['min_value'] >= 0){
					$all_up = true;
				}
			}else{
				$all_down = true;
			}
		}

		//Obtaining Y axis division length in data value
		if (!($all_down) && !($all_up)){
			$y_dig = 0;
			$y_division_value = $y_axis_length;
			if ($y_axis_length < 1){
				while ($y_division_value < 1){
					$y_dig--;
					$y_division_value *= 10;
				}
				$y_dig--;
			}else { 
				while ($y_division_value >= 10){
					$y_dig++;
					$y_division_value /= 10;
				}
				$y_dig--;
			}
	
			$y_division_value = $y_division_value * pow(10, $y_dig);
		}else
			$y_division_value = $y_axis_length/10;

		//If there are both negative and positive data, another y division
		//is going to be needed.
		if (!($all_down) && !($all_up) && (is_null($y_rl)) && (is_null($y_ru))){
			$y_axis_length += $y_division_value;
			$y_axis_slength += $y_division_value;
		}

		//Obtaining how many steps (going downward in the y axis) is the x-axis
		$x_axis_count = floor(($y_axis_length - $y_axis_slength)/$y_division_value);

		//Top and bottom of y-axis
		$y_axis_top = $this->top_border;
		$y_axis_bottom = $this->bottom_border;

		//Obtaining conversion factor from data to pixel count
		$conversion_factor = ($y_axis_bottom - $y_axis_top)/$y_axis_length;
		$y_division_mid = $y_division_value * ($y_axis_bottom - $y_axis_top)/$y_axis_length;

		//Obtaining max Y value
		if (!($all_down) && !($all_up) && (is_null($y_rl)) && (is_null($y_ru)))
			//Thanks to chris (chrego3-1 at yahoo dot fr) for this next line of code
			$max_y_value = ($x_axis_count+1) * ($y_division_value);
		else if(!($all_down) && !($all_up)){
			$x_axis_count--;
			$max_y_value = $specs["max_value"];
		}else
			$max_y_value = $specs["max_value"];


		$current_y_pos = $y_axis_top;
		$current_y_value = $max_y_value;

		//Defining dashed line style
		if($g_per){
			if($g_per > 10) $g_per = 10;
			else if($g_per < 0) $g_per = 0;
			$g_per = ($g_per*2)+80;
			$grid_style=array($this->line_color, $this->line_color);
			for($i=0; $i < 100-$g_per; $i++)
				array_push($grid_style, IMG_COLOR_TRANSPARENT);
			imagesetstyle($this->image, $grid_style);
		}
		
		$max_font_left_space = 0;
		

		//Painting the y-axis
		$line_count = 0;
		while($current_y_pos <= $y_axis_bottom){
			$font_left_space = strlen($current_y_value."")*5;
			if ($max_font_left_space < $font_left_space) $max_font_left_space = $font_left_space;
			if (!$all_down)
				$current_y_pos += $y_division_mid;
			if((($all_up) && ($line_count == ($x_axis_count-1))) || (!($all_up) && ($line_count == $x_axis_count))){
				if ($all_up || ((!$all_down) && (is_null($y_rl)) && (is_null($y_ru))))
					$current_y_value = 0;		//to avoid PHP putting something like "1628E-90" instead of 0
				else
		 			$current_y_value -= $y_division_value;
			}else{
	 			$current_y_value -= $y_division_value;
			}
			if ($all_down)
				$current_y_pos += $y_division_mid;
			$line_count++;
		}
		$font_left_space = strlen($current_y_value."")*5;
		if ($max_font_left_space < $font_left_space) $max_font_left_space = $font_left_space;

		$y_axis_x = $this->left_border+(($max_font_left_space-20));
		imageline($this->image, $y_axis_x, $y_axis_top, $y_axis_x, $y_axis_bottom, $this->line_color);


		//Painting the y divisions
		$y_division_left = $y_axis_x-5;
		$y_division_right = $y_axis_x+5;

		$current_y_pos = $y_axis_top;
		$current_y_value = $max_y_value;

		$x_axis_y = 0;		
		$x_axis_y_value=0;

		$line_count = 0;
		while($current_y_pos <= $y_axis_bottom){
			$font_left_space = strlen($current_y_value."")*5;
			imagestring($this->image, 1, $y_division_left-$font_left_space, $current_y_pos-4, $current_y_value."", $this->font_color);
			imageline($this->image, $y_division_left, $current_y_pos, $y_division_right, $current_y_pos, $this->line_color);
			if($g_per)
				imageline($this->image, $y_division_right, $current_y_pos, $this->right_border, $current_y_pos, IMG_COLOR_STYLED);
			if (!$all_down)
				$current_y_pos += $y_division_mid;
			if((($all_up) && ($line_count == ($x_axis_count-1))) || (!($all_up) && ($line_count == $x_axis_count))){
				$x_axis_y = $current_y_pos;
				if ($all_up || ((!$all_down) && (is_null($y_rl)) && (is_null($y_ru))))
					$current_y_value = 0;		//to avoid PHP putting something like "1628E-90" instead of 0
				else
		 			$current_y_value -= $y_division_value;
				$x_axis_y_value = $current_y_value;
			}else{
	 			$current_y_value -= $y_division_value;
			}
			if ($all_down)
				$current_y_pos += $y_division_mid;
			$line_count++;
		}

		//If there are both negative and positive data, another y division
		//is going to be needed.
		if (!($all_down) && !($all_up)){
			$font_left_space = strlen($current_y_value."")*5;
			imagestring($this->image, 1, $y_division_left-$font_left_space, $current_y_pos-4, $current_y_value."", $this->font_color);
			imageline($this->image, $y_division_left, $current_y_pos, $y_division_right, $current_y_pos, $this->line_color);
			if($g_per)
				imageline($this->image, $y_division_right, $current_y_pos, $this->right_border, $current_y_pos, IMG_COLOR_STYLED);
			$line_count++;
		}

		//Painting the small the extra parts in the above and lower parts
		//of the Y axis
		imageline($this->image, $y_axis_x, $y_axis_top-($y_division_mid/8), $y_axis_x, $y_axis_top, $this->line_color);
		imageline($this->image, $y_axis_x, $y_axis_bottom, $y_axis_x, $y_axis_bottom+($y_division_mid/8), $this->line_color);

		//Getting the y position of the x axis
		if (!($x_axis_y)){
			if($all_down){
				$x_axis_y = $y_axis_top;
			}else{
				$x_axis_y = $y_axis_bottom;
			}
		}else if($x_axis_y > $y_axis_bottom){
			$x_axis_y = $y_axis_bottom;
		}
		
		//Painting X axis
		$x_axis_left = $y_axis_x;
		$x_axis_right = $this->right_border;
		imageline($this->image, $x_axis_left, $x_axis_y, $x_axis_right, $x_axis_y, $this->line_color);
		$x_axis_left = $y_division_right+10;

		//Reversing the array that contains the x axis labels so that they can be obtained by
		//the 'array_pop' PHP function in the right order
		$x_label = array_reverse($x_ls);

		//Painting each line
		$x_division_width = ($x_axis_right - $x_axis_left)/($specs['length']-1);
		foreach($data as $prod => $sub_data){
		//	$currentline_color = imagecolorallocate($this->image, ($color[$prod][0]+0), ($color[$prod][1]+0), ($color[$prod][2]+0));
		$currentline_color = imagecolorallocate($this->image,128,0,128);
			//line thickness;
		//	$currentline_thickness = (is_array($l_t[$prod])) ? (($l_t[$prod][0]+0)==0) ? 2 : $l_t[$prod] : (($l_t[$prod]+0)==0) ? 2 : $l_t[$prod];
			$currentline_thickness = 2;
			
			$current_x_pos = $x_axis_left;
			$past_x = -1;
			$past_y = -1;
			foreach($sub_data as $i => $value){
				if ($all_down)
					$currentpoint_rel_height = ($value-$specs['max_value']) * $conversion_factor;
				else if ($all_up)
					$currentpoint_rel_height = ($value-$specs['min_value']) * $conversion_factor;
				else
					$currentpoint_rel_height = ($value-$x_axis_y_value) * $conversion_factor;
				
				$currentpoint_real_height = $x_axis_y - $currentpoint_rel_height;
				if($inc_dot)
					imagefilledrectangle($this->image, $current_x_pos-2, $currentpoint_real_height-2, $current_x_pos+2, $currentpoint_real_height+2, $currentline_color);
				if ($past_x != -1){
					//Activating the currentline thickness
					imagesetthickness($this->image, $currentline_thickness);
					imageline($this->image, $past_x, $past_y, $current_x_pos, $currentpoint_real_height, $currentline_color);
				}
				if(strcmp($specs['ref_length'],$prod)==0){
					//Reseting thickness of surrounding lines
					imagesetthickness($this->image, $this->line_thickness);
					imageline($this->image, $current_x_pos, $x_axis_y+5, $current_x_pos, $x_axis_y-5, $this->line_color);
					if($g_per){
						imagesetstyle($this->image, $grid_style);
						imageline($this->image, $current_x_pos, $x_axis_y-5, $current_x_pos, $this->top_border, IMG_COLOR_STYLED);
						imageline($this->image, $current_x_pos, $x_axis_y+5, $current_x_pos, $this->bottom_border, IMG_COLOR_STYLED);
					}
					
					//Printing X axis label
					$label = array_pop($x_label);
					$font_left_space = strlen($label."")*5/2;
					imagestring($this->image, 1, $current_x_pos-$font_left_space, $x_axis_y+10, $label."", $this->font_color);
				}
				$past_x = $current_x_pos;
				$past_y = $currentpoint_real_height;
				$current_x_pos += $x_division_width;
			}
		}

		//Reseting thickness of surrounding lines
		imagesetthickness($this->image, $this->line_thickness);

		//Printing Title
		$font_left_space = (strlen($this->title)*7)/2 - 15 ;
		imagestring($this->image, 3, ($this->width/2)-($font_left_space), 0, $this->title, $this->font_color);
		
		//Printing Y Axis Title
//		imagestring($this->image, 3, $y_division_left-$max_font_left_space, 0, $y_t."", $this->font_color);
		imagestring($this->image, 3, 0, 0, $y_t."", $this->font_color);

		//Printing X Axis Title
		$font_left_space = strlen($x_t."")*6 - 15;
		imagestring($this->image, 3, $this->width-$font_left_space, $x_axis_y-12, $x_t ."", $this->font_color);

		//Legend
		if($this->legend){
			if (count($color)>0)
				$this->_do_legend($color);
			else{
				$key = array_keys($data);
				foreach($key as $key => $value){
					$color[$value] = Array(0,0,0);
				}
				$this->_do_legend($color);
			}
		}
		
     	//Printing Footer
		$font_left_space = (strlen($this->Footer)*7)/2;
		imagestring($this->image, 15, ($font_left_space),$x_axis_y +25 , $this->Footer, $this->font_color);

		//Return image
		/*header('Content-type: image/png');
		
		imagepng($this->image);
		imagedestroy($this->image);
*/
        imagejpeg( $this->image, "mypic.jpeg", 90);
        imagedestroy($this->image);
        echo "<img src='mypic.jpeg'><p></p>";
	}

	//Bar Graph.
	//	Array format:
	//		Name of bar=> (value of bar, red, green, blue)
	//	Defaults:
	//		Bar width/Region width = 90%
	//		Black color
	function bar_graph($data, $x_t="", $y_t="", $wi_p=90, $g_per=0, $b_ol=true){
		//Obtaining Y axis length in data value without extra bottom nor top
		$specs = $this->_get_specs($data,"bar");

		//This next section is
		//guaranteeing a completely scalable graph independently if graphing .001 or 1000
		$y_axis_slength = 0;
		$all_down = false;
		$all_up = false;
		if (($specs['max_value'] == 0) && ($specs['min_value'] == 0)){
			$y_axis_length = 10;
			$y_axis_slength = 0;
		}else{
			if ($specs['max_value'] > 0){
				$y_axis_length = $specs["max_value"];
				if ($specs['min_value'] < 0){
					$y_axis_length -= $specs['min_value'];
				}
			}else{
				$y_axis_length = abs($specs["min_value"]);
			}

			$y_dig = 0;
			$y_division_value = $y_axis_length;
			if ($y_axis_length < 1){
				while ($y_division_value < 1){
					$y_dig++;
					$y_division_value *= 10;
				}
			}else {
				$y_dig = 1;
				while ($y_division_value >= 10){
					$y_dig--;
					$y_division_value /= 10;
				}
			}
			
			$y_dig = pow(10,$y_dig+1);

			if ($specs['max_value'] > 0){
				if ($specs['min_value'] < 0){
					$y_axis_length = ceil(($specs["max_value"]*$y_dig)-($specs['min_value']*$y_dig))/$y_dig;
					$y_axis_slength = $y_axis_length-(ceil($specs['max_value']*$y_dig)/$y_dig);
				}else{
					$y_axis_length = ceil($specs["max_value"]*$y_dig)/$y_dig;
					$all_up = true;
				}
			}else{
				$y_axis_length = abs(floor($specs["min_value"]*$y_dig)/$y_dig);
				$y_axis_slength = $y_axis_length;
				$all_down = true;
			}

			//After this:
			//If the numerical length of the y_axis is 3,124, y_axis_length is 3,200
			//if it's 0.002292, y_axis_length is 0.0023, which will become the real
			//numerical length of they y-axis

		}
	
		//Obtaining Y axis division length in data value
		if (!($all_down) && !($all_up)){
			$y_dig = 0;
			$y_division_value = $y_axis_length;
			if ($y_axis_length < 1){
				while ($y_division_value < 1){
					$y_dig--;
					$y_division_value *= 10;
				}
				$y_dig--;
			}else { 
				while ($y_division_value >= 10){
					$y_dig++;
					$y_division_value /= 10;
				}
				$y_dig--;
			}
	
			$y_division_value = $y_division_value * pow(10, $y_dig);
		}else
			$y_division_value = $y_axis_length/10;

		//If there are both negative and positive data, another y division
		//is going to be needed.
		if (!($all_down) && !($all_up)){
			$y_axis_length += $y_division_value;
			$y_axis_slength += $y_division_value;
		}

		//Obtaining how many steps (going downward in the y axis) is the x-axis
		$x_axis_count = floor(($y_axis_length - $y_axis_slength)/$y_division_value);

		//Top and bottom of y-axis
		$y_axis_top = $this->top_border;
		$y_axis_bottom = $this->bottom_border;

		//Obtaining conversion factor from data to pixel count
		$conversion_factor = ($y_axis_bottom - $y_axis_top)/$y_axis_length;
		$y_division_mid = $y_division_value * ($y_axis_bottom - $y_axis_top)/$y_axis_length;

		//Obtaining max Y value
		if ($all_down)
			$max_y_value = 0;
		else if(!($all_down) && !($all_up)){
			//Thanks to chris (chrego3-1 at yahoo dot fr) for this next line of code
			$max_y_value = ($x_axis_count+1) * ($y_division_value);
		}else
			$max_y_value = $specs["max_value"];


		//Defining dashed line style
		if($g_per){
			if($g_per > 10) $g_per = 10;
			else if($g_per < 0) $g_per = 0;
			$g_per = ($g_per*2)+80;
			$style=array($this->line_color, $this->line_color);
			for($i=0; $i < 100-$g_per; $i++)
				array_push($style, IMG_COLOR_TRANSPARENT);
			imagesetstyle($this->image, $style);
		}
		
		$current_y_pos = $y_axis_top;
		$current_y_value = $max_y_value;
		$max_font_left_space = 0;

		//Painting the y-axis
		$line_count = 0;
		while($current_y_pos <= $y_axis_bottom){
			$font_left_space = strlen($current_y_value."")*5;
			if ($max_font_left_space < $font_left_space) $max_font_left_space = $font_left_space;
			if (!$all_down)
				$current_y_pos += $y_division_mid;
			if($line_count == ($x_axis_count-1)){
				$x_axis_y = $current_y_pos;
				if (!$all_down){
					$current_y_value = 0;		//to avoid PHP putting something like "1628E-90" instead of 0
				}else
		 			$current_y_value -= $y_division_value;
			}else{
				$current_y_value -= $y_division_value;
			}
			if ($all_down)
				$current_y_pos += $y_division_mid;
			$line_count++;
		}
		$font_left_space = strlen($current_y_value."")*5;
		if ($max_font_left_space < $font_left_space) $max_font_left_space = $font_left_space;

		$y_axis_x = $this->left_border+(($max_font_left_space-20));
		imageline($this->image, $y_axis_x, $y_axis_top, $y_axis_x, $y_axis_bottom, $this->line_color);


		//Painting y-divisions
		$y_division_left = $y_axis_x-5;
		$y_division_right = $y_axis_x+5;

		$current_y_pos = $y_axis_top;
		$current_y_value = $max_y_value;

		$x_axis_y = 0;		
		$x_axis_y_value=0;

		$line_count = 0;
		while($current_y_pos <= $y_axis_bottom){
			$font_left_space = strlen($current_y_value."")*5;
			imagestring($this->image, 1, $y_division_left-$font_left_space, $current_y_pos-4, $current_y_value."", $this->font_color);
			imageline($this->image, $y_division_left, $current_y_pos, $y_division_right, $current_y_pos, $this->line_color);
			if($g_per)
				imageline($this->image, $y_division_right, $current_y_pos, $this->right_border, $current_y_pos, IMG_COLOR_STYLED);

			if (!$all_down)
				$current_y_pos += $y_division_mid;
//			if((($all_up) && ($line_count == ($x_axis_count-1))) || (!($all_up) && ($line_count == $x_axis_count))){
			if($line_count == $x_axis_count){
				$x_axis_y = $current_y_pos;
				if (!$all_down)
					$current_y_value = 0;		//to avoid PHP putting something like "1628E-90" instead of 0
				else
		 			$current_y_value -= $y_division_value;
			}else{
				$current_y_value -= $y_division_value;
			}
			if ($all_down)
				$current_y_pos += $y_division_mid;
			$line_count++;
		}
		
		$max_font_left_space = 0;
		
		//If there are both negative and positive data, another y division
		//is going to be needed.
		if (!($all_down) && !($all_up)){
			$font_left_space = strlen($current_y_value."")*5;
			imagestring($this->image, 1, $y_division_left-$font_left_space, $current_y_pos-4, $current_y_value."", $this->font_color);
			imageline($this->image, $y_division_left, $current_y_pos, $y_division_right, $current_y_pos, $this->line_color);
			if($g_per)
				imageline($this->image, $y_division_right, $current_y_pos, $this->right_border, $current_y_pos, IMG_COLOR_STYLED);
			$line_count++;
			if ($max_font_left_space < $font_left_space) $max_font_left_space = $font_left_space;
		}

		//Painting the small the extra parts in the above and lower parts
		//of the Y axis
		imageline($this->image, $y_axis_x, $y_axis_top-($y_division_mid/8), $y_axis_x, $y_axis_top, $this->line_color);
		imageline($this->image, $y_axis_x, $y_axis_bottom, $y_axis_x, $y_axis_bottom+($y_division_mid/8), $this->line_color);

		//Obtaining the y position of the x axis
		if (!($x_axis_y)){
			if($all_down){
				$x_axis_y = $y_axis_top;
			}else{
				$x_axis_y = $y_axis_bottom;
			}
		}else if($x_axis_y > $y_axis_bottom){
			$x_axis_y = $y_axis_bottom;
		}

		//Painting X axis
		$x_axis_left = $y_division_right;
		$x_axis_right = $this->right_border;
		imageline($this->image, $x_axis_left, $x_axis_y, $x_axis_right, $x_axis_y, $this->line_color);

		//Painting each bar
		$bar_width = ($x_axis_right - $x_axis_left)/count($data);
		$bar_side_space = $bar_width*((100-abs($wi_p))/200);
		$current_x_pos = $x_axis_right - $bar_width;
		$data_rev = array_reverse($data);
		foreach($data_rev as $prod => $sub_data){
			$currentbar_rel_height = $sub_data[0] * $conversion_factor;
			$currentbar_color = imagecolorallocate($this->image, ($sub_data[1]+0), ($sub_data[2]+0), ($sub_data[3]+0));
			$currentbar_3dcolor = imagecolorallocate($this->image, ($sub_data[1]-50 < 0) ? 0 : $sub_data[1]-50, ($sub_data[2]-50 < 0) ? 0 : $sub_data[2]-50, ($sub_data[3]-50 < 0) ? 0 : $sub_data[3]-50);
			$currentbar_3dwidth = (array_key_exists(4,$sub_data)) ? $sub_data[4]+0 : 0;
			$currentbar_varedge = $x_axis_y-$currentbar_rel_height;
			if ($currentbar_varedge > $x_axis_y){
				//3D Effect
				for($i = 0; $i < $currentbar_3dwidth; $i++)
					imagefilledrectangle($this->image, $current_x_pos+$bar_side_space+$i, $x_axis_y+$i, $current_x_pos+$bar_width-$bar_side_space+$i, $currentbar_varedge+$i, $currentbar_3dcolor);
				imagefilledrectangle($this->image, $current_x_pos+$bar_side_space+$i, $x_axis_y+$i, $current_x_pos+$bar_width-$bar_side_space+$i, $currentbar_varedge+$i, $currentbar_color);
				if($b_ol){
					imagepolygon($this->image,Array(
							$current_x_pos+$bar_side_space, $x_axis_y,
							$current_x_pos+$bar_width-$bar_side_space,$x_axis_y,
							$current_x_pos+$bar_width-$bar_side_space+$i,$x_axis_y+$i,
							$current_x_pos+$bar_side_space+$i,$x_axis_y+$i
					),4,$this->line_color);
					imagepolygon($this->image,Array(
							$current_x_pos+$bar_side_space, $x_axis_y,
							$current_x_pos+$bar_side_space+$i,$x_axis_y+$i,
							$current_x_pos+$bar_side_space+$i,$currentbar_varedge+$i,
							$current_x_pos+$bar_side_space,$currentbar_varedge
					),4,$this->line_color);
					imagerectangle($this->image, $current_x_pos+$bar_side_space+$i, $x_axis_y+$i, $current_x_pos+$bar_width-$bar_side_space+$i, $currentbar_varedge+$i, $this->line_color);
				}
			}else{
				//3D Effect
				for($i = 0; $i < $currentbar_3dwidth; $i++)
					imagefilledrectangle($this->image, $current_x_pos+$bar_side_space+$i, $currentbar_varedge+$i, $current_x_pos+$bar_width-$bar_side_space+$i, $x_axis_y+$i, $currentbar_3dcolor);
				imagefilledrectangle($this->image, $current_x_pos+$bar_side_space+$i, $currentbar_varedge+$i, $current_x_pos+$bar_width-$bar_side_space+$i, $x_axis_y+$i, $currentbar_color);
				if($b_ol){
					imagepolygon($this->image,Array(
							$current_x_pos+$bar_side_space, $currentbar_varedge,
							$current_x_pos+$bar_width-$bar_side_space, $currentbar_varedge,
							$current_x_pos+$bar_width-$bar_side_space+$i, $currentbar_varedge+$i,
							$current_x_pos+$bar_side_space+$i, $currentbar_varedge+$i
					),4,$this->line_color);
					imagepolygon($this->image,Array(
							$current_x_pos+$bar_side_space, $x_axis_y,
							$current_x_pos+$bar_side_space+$i,$x_axis_y+$i,
							$current_x_pos+$bar_side_space+$i,$currentbar_varedge+$i,
							$current_x_pos+$bar_side_space,$currentbar_varedge
					),4,$this->line_color);
					imagerectangle($this->image, $current_x_pos+$bar_side_space+$i, $x_axis_y+$i, $current_x_pos+$bar_width-$bar_side_space+$i, $currentbar_varedge+$i, $this->line_color);
				}
			}
			$font_left_space = (strlen($prod)*5)/2;
			imagestring($this->image, 2, $current_x_pos+($bar_width/2)-($font_left_space)+$i, $x_axis_y+$i, $prod, $this->font_color);

			$current_x_pos -= $bar_width;
		}
		
		//Printing Title
		$font_left_space = (strlen($this->title)*7)/2;
		imagestring($this->image, 3, ($this->width/2)-($font_left_space), 0, $this->title, $this->font_color);
		
		//Printing Y Axis Title
		imagestring($this->image, 2, $y_division_left-$max_font_left_space, 0, $y_t."", $this->font_color);

		//Printing X Axis Title
		$font_left_space = strlen($x_t."")*6;
		imagestring($this->image, 2, $this->width-$font_left_space, $x_axis_y-12, $x_t."", $this->font_color);

		//Printing Legend
		if($this->legend){
			$legend_data = Array();
			foreach($data as $prod => $sub_data){
				$legend_data[$prod] = Array($sub_data[1],$sub_data[2],$sub_data[3]);
			}
			$this->_do_legend($legend_data);
		}

		//Return image
		header('Content-type: image/png');
		imagepng($this->image);
		imagedestroy($this->image);
	}

	//Pie Graph.
	//	Array format:
	//		Name of pie slice => (absolute value of slice, red, green, blue)
	//	Defaults:
	//		Black color
	//		Pie filling 90% of the image
	//		With piece labels
	//		Start at 0 degrees
	//		No 3D effect in anyone
	//		1 pixel line thickness
	function pie_graph($data, $p_o=90, $put_pieces=true, $degree_start=0, $put_l=true, $threed_thickness=Array()){
		//Get center of pie
		$pie_center_x = ($this->right_border + $this->left_border)/2;
		$pie_center_y = ($this->top_border + $this->bottom_border)/2;
		$pie_width = ($this->right_border - $this->left_border)*$p_o/100;
		$pie_height = ($this->bottom_border - $this->top_border)*$p_o/100;

		//Draw lines, fill with color and label each pie slice
		$specs = $this->_get_specs($data,"pie");
		$data_total_elements = count($data);
		
		$max_threed_thickness = 0;
		if (count($threed_thickness) > 0){
			$max_threed_thickness = max($threed_thickness)+0;
		}
		
		for ($i = 0; $i <= $max_threed_thickness; $i++){
			$total_degree_width = 0;
			$curr_ele = 1;
			foreach($data as $prod => $subarray){
				//Getting degree width of slice
				if ($curr_ele == $data_total_elements){
					$degree_width = 360 - $total_degree_width;
	
					//Thanks for Nam Phando for this next three lines.
					//The last value of the array can have a negative value
					//because of rounding errors, so these takes care of it.
					if ($degree_width < 0){
						$degree_width = 0;
					}
				}else{
					//Usage of round, recommended by Nam Phando.
					$degree_width = round((($subarray[0]+0) / $specs['total'])*360);
				}

				$curr_ele++;
								
				if ($i == $threed_thickness[$prod]+0){		
					//Obtaining the color of this slice
					$curr_color = imagecolorallocate($this->image,$subarray[1]+0,$subarray[2]+0,$subarray[3]+0);

					//Drawing slice with its color
					imagefilledarc($this->image, $pie_center_x, $pie_center_y-$threed_thickness[$prod], $pie_width, $pie_height, $degree_start+$total_degree_width, $degree_start+$total_degree_width+$degree_width, $curr_color,IMG_ARC_PIE);
		
					//Drawing top outline and side outline
					if($put_l){
						imagefilledarc($this->image, $pie_center_x, $pie_center_y-$threed_thickness[$prod], $pie_width, $pie_height, $degree_start+$total_degree_width, $degree_start+$total_degree_width+$degree_width, $this->line_color,IMG_ARC_NOFILL | IMG_ARC_EDGED);
						if ((floor(($degree_start+$total_degree_width)/180)%2) == 0){
							$ver_line_pos = $this->_ellipse_pos($degree_start+$total_degree_width, $pie_height, $pie_width, "");
							imageline($this->image, $pie_center_x+$ver_line_pos['x'], $pie_center_y+$ver_line_pos['y'], $pie_center_x+$ver_line_pos['x'], $pie_center_y+$ver_line_pos['y']-$threed_thickness[$prod], $this->line_color);
						}
						
						if ((floor(($degree_start+$total_degree_width+$degree_width)/180)%2) == 0){
							$ver_line_pos = $this->_ellipse_pos($degree_start+$total_degree_width+$degree_width, $pie_height, $pie_width, "");
							imageline($this->image, $pie_center_x+$ver_line_pos['x'], $pie_center_y+$ver_line_pos['y'], $pie_center_x+$ver_line_pos['x'], $pie_center_y+$ver_line_pos['y']-$threed_thickness[$prod], $this->line_color);
						}
					}
					//Printing label
					if($put_pieces){
						$label_pos = $this->_ellipse_pos($degree_start+$total_degree_width+($degree_width/2), $pie_height, $pie_width, $prod."");
						imagestring($this->image, 2, $pie_center_x+$label_pos['x'], $pie_center_y+$label_pos['y']-$threed_thickness[$prod], $prod."", $this->font_color);
					}
				}else if ($i < $threed_thickness[$prod]+0){
					//Obtaining the color of the 3D side of this slice
					$curr_3dcolor = imagecolorallocate($this->image, ($subarray[1]-50 < 0) ? 0 : $subarray[1]-50, ($subarray[2]-50 < 0) ? 0 : $subarray[2]-50, ($subarray[3]-50 < 0) ? 0 : $subarray[3]-50);

					//Drawing bottom outline of pie in 3d
					if($put_l and $i == 0)
						imagefilledarc($this->image, $pie_center_x, $pie_center_y, $pie_width+1, $pie_height+1, $degree_start+$total_degree_width, $degree_start+$total_degree_width+$degree_width, $this->line_color,IMG_ARC_NOFILL | IMG_ARC_EDGED);
					//Creating 3D effect
					imagefilledarc($this->image, $pie_center_x, $pie_center_y-$i, $pie_width, $pie_height, $degree_start+$total_degree_width, $degree_start+$total_degree_width+$degree_width, $curr_3dcolor,IMG_ARC_PIE);
				}

				//Getting starting point of next slice
				$total_degree_width+=$degree_width;
			}
		}

		//Printing title
		$font_left_space = (strlen($this->title)*7)/2;
		imagestring($this->image, 3, ($this->width/2)-($font_left_space), 0, $this->title, $this->font_color);

		//Printing legend
		if($this->legend){
			$legend_data = Array();
			foreach($data as $prod => $sub_data){
				$legend_data[$prod] = Array($sub_data[1],$sub_data[2],$sub_data[3]);
			}
			$this->_do_legend($legend_data);
		}
		
		//Return image
		header('Content-type: image/png');
		imagepng($this->image);
		imagedestroy($this->image);
	}





	
	/****************** Protected methods *******************/
	//Gets the highest value, lowest value, and average out of an array.
	function _get_specs($data, $type){
		switch($type){
			case "line":
				$longest = 0;
				$longest_index = "";

				//Thanks to Mathieu Davy for detecting the absence of this next line
				$max = $data[key($data)][0];
				$min = $data[key($data)][0];	//get the first element to search for
												//lowest and highest value
				foreach($data as $i => $sub_array){
					$this_max = max($sub_array);
					$this_min = min($sub_array);
					$length = count($sub_array);
					if($max < $this_max){
						$max = $this_max;
					}
					if($min > $this_min){
						$min = $this_min;
					}
					if($longest < $length){
						$longest = $length;
						$longest_index = $i;
					}
				}
				return Array("max_value" => $max,"min_value" => $min, "length" => $longest, "ref_length" => $longest_index);

			case "bar":
				$max = $data[key($data)][0];
				$min = $data[key($data)][0];	//get the first element to search for
												//lowest and highest value
				foreach($data as $i => $sub_array){
					if($max < $sub_array[0]){
						$max = $sub_array[0];
					}
					if($min > $sub_array[0]){
						$min = $sub_array[0];
					}
				}
				return Array("max_value" => $max,"min_value" => $min);
			
			case "pie":
				$total = 0;
				foreach($data as $i => $sub_array){
					$total += $sub_array[0];
				}
				return Array("total" => $total);
			break;
		}
	}
	
	//Displays the legend
	//	Array format:
	//		Name => (red, green, blue)
	function _do_legend($data){
		//Getting the width and height of the legend
		$longest_name_length = 0;
		$legend_height = 0;
		foreach($data as $name => $sub_data){
			if (strlen($name) > $longest_name_length) $longest_name_length = strlen($name);
			$legend_height += 10;
		}

		$legend_width = ($longest_name_length*5)+18;

		//Getting the x position of the left corner of the legend
		if (($this->legend_x > $this->right_border) || is_null($this->legend_x))
		//	$this->legend_x = $this->right_border - $legend_width;
		$this->legend_x = $this->right_border + 10;
		else if ($this->legend_x < $this->left_border)
			$this->legend_x = $this->left_border;
		
		$current_x_pos = $this->legend_x ;

		//Getting the y position of the left corner of the legend
		if (($this->legend_y < ($this->top_border)) || is_null($this->legend_y))
			$this->legend_y = $this->top_border;
		else if ($this->legend_y > $this->bottom_border - $legend_height)
			$this->legend_y = $this->bottom_border - $legend_height;

		$current_y_pos = $this->legend_y + 1;

		//Printing the titles and colors of the data
		foreach($data as $name => $sub_data){
			$current_color = imagecolorallocate($this->image, ($sub_data[0]+0), ($sub_data[1]+0), ($sub_data[2]+0));
			imagefilledrectangle($this->image, $current_x_pos+3,$current_y_pos+1, $current_x_pos+8,$current_y_pos+6,$current_color);
			imagestring($this->image, 1, $current_x_pos+16, $current_y_pos, $name, $this->font_color);
			$current_y_pos += 10;
		}

		//Printing legend border
		if($this->legend_border)
			imagerectangle($this->image, $this->legend_x, $this->legend_y, $this->legend_x+$legend_width, $this->legend_y+$legend_height, $this->line_color);
	}
	
	//Returns the true position of a label given the height, width and radius of an ellipse
	function _ellipse_pos($degree, $ellipse_height, $ellipse_width, $prod){
		//Obtaining segments a and b from ellipse
		$ellipse_a = ceil($ellipse_width/2);
		$ellipse_b = ceil($ellipse_height/2);
		$ellipse_a2 = pow($ellipse_a,2);
		$ellipse_b2 = pow($ellipse_b,2);

		//Proportion from this ellipse between x and y
		$e = $ellipse_height/$ellipse_width;
		$circle_radius = ($ellipse_height > $ellipse_width) ? $ellipse_height : $ellipse_width;
	
		//Obtaining Y of the circle from which this ellipse was squished from
		$circle_angle_x = $circle_radius*cos(deg2rad($degree));
		$circle_angle_y = $circle_radius*sin(deg2rad($degree));
		if ($ellipse_height > $ellipse_width){
			//Obtaining x for this ellipse, because we know that if we're here, $circle_angle_y == $label_y
			$circle_angle_x = $circle_angle_x/$e;
		}else{
			//Obtaining y for this ellipse, because we know that if we're here, $circle_angle_x == $label_x
			$circle_angle_y = $circle_angle_y*$e;
		}
	
		$label_angle = rad2deg(atan($circle_angle_y/$circle_angle_x));
		if($circle_angle_y < 0 && $circle_angle_x < 0){
			$label_angle += 180;
		}else if($circle_angle_y < 0){
			$label_angle = 360 + $label_angle;
		}else if($circle_angle_x < 0){
			$label_angle += 180;
		}
		
		$label_radius = round(sqrt($ellipse_b2*$ellipse_a2/(($ellipse_b2*pow(cos(deg2rad($label_angle)),2))+($ellipse_a2*pow(sin(deg2rad($label_angle)),2)))));

		if (strlen($prod."") > 0){
			if($label_angle > 90 && $label_angle < 180){
				$label_radius += (abs(strlen($prod."")*3)*abs(sin(deg2rad($label_angle-90))));
			}else if($label_angle >= 180 && $label_angle <= 270){
				$label_radius += (abs(strlen($prod."")*3)*abs(sin(deg2rad($label_angle-90))))+(10*abs(sin(0.5*deg2rad($label_angle))));
			}else if($label_angle > 270){
				$label_radius -= (abs(strlen($prod."")*3/2)*abs(sin(deg2rad($label_angle-90))));
			}
		}

		return Array('x' => $label_radius*cos(deg2rad($label_angle)), 'y' => $label_radius*sin(deg2rad($label_angle)));
	}
}}

?>
this if for report

Code: Select all

   
<?php
    require_once("gdgraph.php");
    include("include/database.inc");
//	require_once("include/general.inc");
    
    session_start();
	if (isset($_SESSION['username']) && isset($_SESSION['company'])) {
		$USERNAME = $_SESSION['username'];
		$COMPANY = $_SESSION['company'];
		$user_nm = $_SESSION['name'];
	}
	
	$dbObj = dbConnect();
			
	/* check connection */
	if (mysqli_connect_errno()) {
		$sts = "Connect failed: ". mysqli_connect_error();
		exit();
	}

	db_access_right("report9", $COMPANY, $USERNAME);
	
	if ($OPEN_ALLOW != 1) {
		echo "<br /><br /><center><span style='color: red; font-weight: bold;'>Anda tidak mempunyai kebenaran BUKA form!</span></center><br /><br />";
		exit();
    } 
	
	Function FmtDateShort2($val) {
		return date(_DATE_FORMAT, strtotime($val)); // YYYY-MM-DD
	}

	Function FmtDateLong2($val) {
		//return date(_DATE_FORMAT." H:i:s", strtotime($val)); // YYYY-MM-DD HH:mm:ss
		return date(_DATE_FORMAT." H:i", strtotime($val)); // YYYY-MM-DD HH:mm
	}

	$sys_maklumat = "";
	$sys_maklumat_nm = ""; 
	$perihal_nm = "";
	$sys_maksud_nm = "";
	$bil = 0;
	$Process=FALSE;

	if (isset($_GET['_maksud'])) $_maksud = $_GET['_maksud'];
	if (isset($_GET['_maklumat'])) $_maklumat = $_GET['_maklumat'];
	if (isset($_GET['_year'])) $_year = $_GET['_year'];
	if (isset($_GET['_perihal'])) $_perihal = $_GET['_perihal'];

	Function lColor($i){
       switch ($i) {
         case 0:
           return "153,204,50";//$YellowGreen=
           break;
         case 1:
		   return "128;0;128";//purple
           break;
         case 2:
    	   return "84;255;159";//SeaGreen1
         case 3:
    	   return "240;128;128";//LightCoral
           break;
         case 4:
    	   return "255;36;0";//Orange Red
           break;
         case 5:
    	   return "255;20;147";//DeepPink
           break;
         case 6:
    	   return "255;255;0";//yellow
           break;
         case 7:
    	   return "153;50;204";//DarkOrchid
           break;
         case 8:
    	   return "255;28;174";//Spicy Pink
           break;
         case 9:
    	   return "255;228;225";//MistyRose
           break;
         case 10:
    	   return "199;21;133";//MediumVioletRed
           break;
         case 11:
    	   return "205;92;92";//IndianRed
           break;
         case 12:
    	   return "255;127;0";//Orange
           break;
         default:
    	   return "0,0,0";//Black

        } 
    
	}
	
    Function FmtDateShort($val) {
		return date("d-m-Y", strtotime($val)); // YYYY-MM-DD
	}


	Function control_where($retrict_field_nm, $formatted_un) {
	    return " (".$retrict_field_nm." IN (SELECT ma_group_co.sys_jabatan FROM ma_user INNER JOIN ma_group_co ON ma_group_co.ma_co=ma_user.ma_co AND ma_group_co.ma_group=ma_user.ma_group AND ma_group_co.sts=1 WHERE ma_user.ma_co='".$GLOBALS['COMPANY']."' AND ma_user.un='".$formatted_un."' )) ";
	}
	Function db_access_right($form, $co, $un) {
///		$mdb = mysqli_connect(_db_host, _db_user, _db_password, _db_name, _db_port);
		
		/* check connection */
//		if (mysqli_connect_errno()) {
//			exit();
//		} 
	$dbObj = dbConnect();
			
	/* check connection */
	if (mysqli_connect_errno()) {
		$sts = "Connect failed: ". mysqli_connect_error();
		exit();
	}

		$query = " SELECT t1.fopen, t1.fread, t1.fnew, t1.fold, t1.fdel FROM ma_access ".
		         " AS t1 INNER JOIN ma_user AS t2 ON t2.ma_co=t1.ma_co AND t2.ma_group=t1.ma_group ".
		         " AND t2.un='".$dbObj->real_escape_string($un)."' AND t2.sts=1 WHERE t1.ma_co='".$dbObj->real_escape_string($co)."'".
		         " AND t1.ma_form='".$dbObj->real_escape_string($form)."' AND t1.sts=1 ";
		
		if ($result = $dbObj->query($query)) {
			$row = $result->fetch_row();
			$GLOBALS['OPEN_ALLOW'] = $row[0];
			$GLOBALS['READ_ALLOW'] = $row[1];
			$GLOBALS['NEW_ALLOW'] = $row[2];
			$GLOBALS['EDIT_ALLOW'] = $row[3];
			$GLOBALS['DEL_ALLOW'] = $row[4];
			$result->free();
		}
		else {
			$GLOBALS['OPEN_ALLOW'] = 0;
			$GLOBALS['READ_ALLOW'] = 0;
			$GLOBALS['NEW_ALLOW'] = 0;
			$GLOBALS['EDIT_ALLOW'] = 0;
			$GLOBALS['DEL_ALLOW'] = 0;
		}
		$dbObj->close();
	}

	$sTahunKewangan = date('Y');
	$sTahunSebelum = date('Y');

	$query = " SELECT tutuplaporan, tutupmasuk,tahunkewangan FROM sys_config ".
    		 " WHERE ma_co='".$dbObj->real_escape_string($COMPANY)."' AND (1=".$READ_ALLOW.") ; ";
	if ($ddl = $dbObj->query($query)) {
		while($gvr = mysqli_fetch_array($ddl)) { 
			$sTahunKewangan = stripslashes($gvr['tahunkewangan']);
			if (stripslashes($gvr['tutuplaporan']) == 1 ) {
				$sTahunSebelum = stripslashes($gvr['tahunkewangan']);
			}
			else {
				$sTahunSebelum = stripslashes($gvr['tahunkewangan']) - 1;
			}
		}
	}	
	
	$sCriteria = " AND (".control_where("sys_jabatan", $dbObj->real_escape_string($USERNAME)).") ";
			  if (isset($_GET['_maksud'])) $sCriteria .= " AND sys_maksud='".$dbObj->real_escape_string($_maksud)."' ";
			  if (isset($_GET['_year'])) $sCriteria .= " AND fiscal_year='".$dbObj->real_escape_string($_year)."' ";
			  if (isset($_GET['_maklumat'])) $sCriteria .= " AND sys_maklumat='".$dbObj->real_escape_string($_maklumat)."' ";
	$sCriteria .= " AND ( fiscal_year = '".$dbObj->real_escape_string($sTahunKewangan)."' OR fiscal_year = '".$dbObj->real_escape_string($sTahunSebelum)."' ) ";

	
	$query = " SELECT sys_maksud_nm,".
             " sys_maklumat, sys_maklumat_nm, nm,sys_jajahan_nm FROM pj_perihal  WHERE (sts=1)  ";
	if (isset($_GET['_perihal'])) $query .= " AND cd='".$dbObj->real_escape_string($_perihal)."' ";
    $query .= $sCriteria ;
	$query .= " ; ";

//	echo $query;
 	if ($gv = $dbObj->query($query)) {
		if ($gvr = mysqli_fetch_array($gv)) {
			$sys_maksud_nm = stripslashes($gvr['sys_maksud_nm']);
			$sys_maklumat = stripslashes($gvr['sys_maklumat']);
			$sys_maklumat_nm  = stripslashes($gvr['sys_maklumat_nm']);
			$perihal_nm  = stripslashes($gvr['nm']);	
	
		}
	}

?>


<html>
<head>
	<title></title>
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />

    <link href="css/StyleSheet2.css" rel="stylesheet" type="text/css" />
</head>
<body class="LandscapeDiv">

	<div style="clear:both;">
	<div style="float:right;"><input type="button" value="Cetak" style="width:70px;" onClick="javascript:window.print(document.getElementById('wrapper2'));" /></div>
	<div>

	<div id="wrapper2" class="LandscapeDiv">
	
		<div id="title">Graf Kemajuan Perihal Projek</div>

		<div style="height:9px;">&nbsp;</div>

		<table border="0" cellpadding="0" cellspacing="0">
			<tr>
				<td width="170px">Maksud Pembangunan</td>
				<td width="10px">:</td>
				<td><?php echo $_maksud." - ".$sys_maksud_nm; ?></td>
			</tr>
			<tr>
				<td width="170px">Tahun Kewangan</td>
				<td width="10px">:</td>
				<td><?php echo $_year;?></td>
			</tr>
			<tr>
			    <td width="170px">Projek</td>
			    <td width="10px">:</td>
				<td><?php echo $sys_maklumat." - ".$sys_maklumat_nm;?></td>
			</tr>
        	<tr>
			    <td width="170px">Perihal Projek</td>
			    <td width="10px">:</td>
				<td><?php echo $_perihal." - ".$perihal_nm;?></td>
		    </tr>


		</table>

		<div style="height:9px;">&nbsp;</div>

		<table border="0" cellpadding="0" cellspacing="0" class="grid" width="1100px">
			<tr> 
			    <th width="50px">Bil.</th>
				<th width="120px">Tarikh</th>
				<th width="180px">Kemajuan Fizikal (%)</th>
				<th align="left">Activiti </th>
			</tr>
		
			<?php
			
			   $arrKemajuan = array();
			   $arrColor =array();
			   $arrLables = array();
			   $arrPerihal =array();
   			   $arrKemajuan2 = array();
			   $arrColor2 =array();
			   $arrLables2 = array();
		       $thicknesses = array();
			   

				$query1 = " SELECT DISTINCT sys_perihal ".
						  " FROM pj_kemajuan ".
						  " WHERE (sts=1)  AND (".control_where("sys_jabatan", $dbObj->real_escape_string($USERNAME)).") ";
				if (isset($_GET['_maksud'])) $query1 .= " AND sys_maksud='".$dbObj->real_escape_string($_maksud)."' ";
				if (isset($_GET['_year'])) $query1 .= " AND fiscal_year='".$dbObj->real_escape_string($_year)."' ";
			    if (isset($_GET['_maklumat'])) $query1 .= " AND sys_maklumat='".$dbObj->real_escape_string($_maklumat)."' ";   
			    if (isset($_GET['_perihal'])) $query1 .= " AND sys_perihal='".$dbObj->real_escape_string($_perihal)."' ";

			    $query1 .= " AND ( fiscal_year = '".$dbObj->real_escape_string($sTahunKewangan)."' OR fiscal_year = '".$dbObj->real_escape_string($sTahunSebelum)."' ) ORDER BY sys_perihal ; ";
			   
			    if ($gv0 = $dbObj->query($query1)) {
					if ($gv0->num_rows == 0) {
						echo "	<tr style='page-break-inside: auto;'>";
						echo "		<td colspan=\"14\" class=\"norecord\">No Record Found</td>";
						echo "	<tr>";
					}
					else{
						while ($gvr0 = mysqli_fetch_array($gv0)) {
					       $arrPerihal[]=stripslashes($gvr0['sys_perihal']);
					      // echo stripslashes($gvr0['sys_perihal']);
						}
			             mysqli_free_result($gv0);
		         $cnt=0;
		         $pCnt=0;
		         $color2=0;
		       
			   foreach ($arrPerihal as $valPerihal) {
			    $pCnt +=1;			
/*				$query1 = " SELECT  (SELECT COUNT(DISTINCT(MONTHNAME(dt_semak))) as a FROM pj_kemajuan t1 WHERE t1.sys_perihal=t2.sys_perihal) AS cnt,sys_perihal,sys_perihal_nm,MONTHNAME(dt_semak) AS dt_semak,kemajuan_fizikal ". */
				$query1 = " SELECT  (SELECT COUNT(dt_semak) as a FROM pj_kemajuan t1 WHERE t1.sys_perihal=t2.sys_perihal) AS cnt".
						",sys_perihal,sys_perihal_nm,DATE(dt_semak)AS dt_semak,dt_diberi,kemajuan_fizikal,activiti ".
						  " FROM pj_kemajuan t2 ".
						  " WHERE (sts=1)  AND (".control_where("sys_jabatan", $dbObj->real_escape_string($USERNAME)).") ".
						  " AND sys_perihal = '".$dbObj->real_escape_string($valPerihal)."' ";
				if (isset($_GET['_maksud'])) $query1 .= " AND sys_maksud='".$dbObj->real_escape_string($_maksud)."' ";
				if (isset($_GET['_year'])) $query1 .= " AND fiscal_year='".$dbObj->real_escape_string($_year)."' ";
			    if (isset($_GET['_maklumat'])) $query1 .= " AND sys_maklumat='".$dbObj->real_escape_string($_maklumat)."' ";
				
			    $query1 .= " AND ( fiscal_year = '".$dbObj->real_escape_string($sTahunKewangan)."' OR fiscal_year = '".$dbObj->real_escape_string($sTahunSebelum)."' ) ORDER BY dt_semak ; ";

//				echo $query1;
				$rowno = 0;

				if ($gv1 = $dbObj->query($query1)) {
					if ($gv1->num_rows == 0) {
						echo "	<tr style='page-break-inside: auto;'>";
						echo "		<td colspan=\"14\" class=\"norecord\">No Record Found</td>";
						echo "	<tr>";
					}
					else {
						while ($gvr1 = mysqli_fetch_array($gv1)) {
						    $rowno += 1;
							$cd = stripslashes($gvr1['sys_perihal']);
							$nm = stripslashes($gvr1['sys_perihal_nm']);
							$kemajuan = stripslashes($gvr1['kemajuan_fizikal']);
							$dt_semak = FmtDateShort(stripslashes($gvr1['dt_semak']));
//							echo "Date".$dt_semak."<br/>";
//							echo "Date2".FmtDateShort($dt_semak)."<br/>";
///							echo "Date".FmtDateShort2(stripslashes($gvr1['dt_diberi']))."<br/>";
							$cnt = stripslashes($gvr1['cnt']);
							$activiti = stripslashes($gvr1['activiti']);

						    if ($cnt > 1){
							    $Process=TRUE;
						     }
			
							$arrKemajuan[]=$kemajuan;
							$arrLables[]=$dt_semak;
							$arrKemajuan2[$valPerihal][]=$kemajuan;
							$arrLables2[]=$dt_semak;

							echo "	<tr>";
							echo "		<td align=\"right\">".$rowno."</td>";
//							echo "		<td>".$cd."</td>";
//							echo "		<td>".$nm."</td>";
							echo "		<td align=\"left\">&nbsp;".($dt_semak)."</td>";
							echo "		<td align=\"right\">&nbsp;".$kemajuan."</td>";
							echo "		<td align=\"left\">&nbsp;".$activiti."</td>";
							echo "	</tr>";
							
						}
					}
				}
     		      //  $arrColor2[$valPerihal][] = lColor($pCnt);
			      $arrColor2[]  =lColor($pCnt);
     		      $thicknesses[]=10;

			}//for each
			
			   }
		   }
			?>


		</table>
        <div style="text-align: center;">
        <br/>
<?php

if ($Process){
$gdg = new GDGraph(600,400,strtoupper("Kemajuan ".$perihal_nm),"");
$gdg->line_graph($arrKemajuan2, $arrColor2, $arrLables2,"Tarikh","%",false);

}else
{
	echo "Maklumat Tidak Lengkap Untuk Lakar Graf, Tarikh Disemak Mesti Lebih Daripada Satu!!";
}
//  $gdg->line_graph($arrKemajuan2, $arrColor2, $arrLables2);
?>

        </div>
		
		<br />
		&nbsp;

		<div style="clear:both;padding-top:3px;">
		<div style="float:left;">Cetak Oleh: <?php echo $user_nm; ?></div>
		<div style="float:right;">Cetak Pada: <?php echo date('d-m-Y H:i:s'); ?></div>
		</div>

		<br />
		&nbsp;

	</div>

<?php

//  foreach ($arrPerihal as $valPerihal) {
//  }
/*
foreach( $arrKemajuan2 as $key => $value ) {
    
     foreach ($value as $value2) {
        echo $key."--".$value2."<br/>";
    }
}
foreach( $arrLables2 as $key => $value ) {
    
     foreach ($value as $value2) {
        echo $key."--".$value2."<br/>";
    }
}
foreach( $arrColor2 as $key => $value ) {
    
     foreach ($value as $value2) {
        echo $key."--".$value2."<br/>";
    }
} */

?>
</body>
</html>
Please guide me

Re: Problem is Graph

Posted: Wed Feb 09, 2011 8:55 am
by John Cartwright
Add

Code: Select all

error_reporting(E_ALL); 
ini_set('display_errors', true);
to the top of your file to enable errors being shown. Otherwise, check your php error log and post any relevant errors.

If that doesn't work (because of a fatal error), you will need to set these configurations in your php.ini and restart apache.

//rant
Nothing personal, but it seems like nobody knows to enable error reporting these days. :banghead:
//end rant