Location: PHPKode > projects > phpCAMALEO > common/fun2inc/bar_graph.inc
<?php
if(!function_exists('bar_graph'))
{
	#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
	#	Prepare bar graph
	#
	#		Input:
	#			$data_offset	= offset index to the value array
	#			$fields_record	= fields per record
	#			$table_field	= table data
	#			$max_width		= max width of bar (in pixels)
	#			$show			= true: show table and build $graph_ary
	#							  false: build $graph_ary
	#			$height			= height of bar (in pixels)
	#
	#		Output:
	#			$graph_ary
	#			$tot_value
	#
	function bar_graph($data_offset, 
					  $fields_record, 
					  $table_field, 
					  $max_width = 60, 
					  $show = false, 
					  $height = 10)
	#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
	{
		global $tot_value;
		$fields_offset=$fields_record-$data_offset-1;
		if($show=='') { $show=false; }
		if($max_width==0) { $max_width=60; }
		#
		#	Build graph array with values
		#
		$temp=count($table_field);
		$ii=0;
		for($i=0;$i<$temp;)
		{
			$i=($ii*$data_offset)+$ii+$data_offset+($ii*$fields_offset);
			if($i<=$temp) { $graph_ary[$i]=$table_field[$i]; }
			$ii++;
		}
		#
		#	Check for max value
		#
		foreach($graph_ary as $value)
		{
			if((isset($max_value) && ($value>$max_value)) || (!isset($max_value)))	{ $max_value=$value; }
			$tot_value=$tot_value+$value;
		}
		$pixels_per_value=((double)$max_width)/$max_value;
		if($show==true) { ?><table cellpadding="5" border="1"><?php };
		$i=0;
		$index=0;
		foreach($graph_ary as $name=>$value)
		{
			$bar_width=$value*$pixels_per_value;
			$index=($i*$data_offset)+$i+$data_offset+($i*$fields_offset);
			if($show==true)
			{
				?><tr>
					<td><?=$name?>&nbsp;(<?=$value?>)</td>
					<td><img src="../../<?=$_SESSION[misc][TBL_BARGRAPH_IMG]?>" width="<?=$bar_width?>" height="10" /></td>
					<td><?=$table_field[$index]?>&nbsp;[<?=$index?>]</td>
				</tr><?php
			}
			#
			#	Update graph array with bar
			#
			$graph_ary[$index]='<img src="../../'.$_SESSION[misc][TBL_BARGRAPH_IMG].'" width="'.$bar_width.'" height="10" />';
			$i++;
		}
		if($show==true) { ?></table><?php };
		return($graph_ary);
	}
}
?>
Return current item: phpCAMALEO