<?php
function createImage($data,$twidth,$tspace,$height){
            $dataName = array();
            $dataValue = array();
            $i = 0;
            $j = 0;
            $k = 0;
            $num = sizeof($data);
            
             foreach($data as $key => $val){
                    $dataName[] = $key;
                    $dataValue[] = $val;
                 }
    
            $maxnum = max($data);
			$tempmun=ceil($maxnum/$height)*10;
           // $width = ($twidth + $tspace) * $num + 4;//image's width
          	$width=700;
		    $im = imagecreate($width +70,$height+50);
            $lineColor = imagecolorallocate($im,12,12,12);
            $bgColor = imagecolorallocate($im,255,255,255);
            $tColor = imagecolorallocate($im,123,200,56);
			$aeraColor[0]=imagecolorallocate($im,255,0,0);
			$aeraColor[1]=imagecolorallocate($im,255,153,0);
			$aeraColor[2]=imagecolorallocate($im,153,204,0);
			$aeraColor[3]=imagecolorallocate($im,0,155,52);
			$aeraColor[4]=imagecolorallocate($im,113,15,141);
			$aeraColor[5]=imagecolorallocate($im,51,204,204);
			$aeraColor[6]=imagecolorallocate($im,51,102,255);
			$aeraColor[7]=imagecolorallocate($im,0,51,205);
			$aeraColor[8]=imagecolorallocate($im,102,51,153);
			$aeraColor[9]=imagecolorallocate($im,153,0,153);
			$aeraColor[10]=imagecolorallocate($im,102,102,255);
			
			$aeraColor1[0]=imagecolorallocate($im,204,0,0);
			$aeraColor1[1]=imagecolorallocate($im,204,102,0);
			$aeraColor1[2]=imagecolorallocate($im,102,153,0);
			$aeraColor1[3]=imagecolorallocate($im,0,104,50);
			$aeraColor1[4]=imagecolorallocate($im,102,0,102);
			$aeraColor1[5]=imagecolorallocate($im,0,153,153);
			$aeraColor1[6]=imagecolorallocate($im,51,51,204);
			$aeraColor1[7]=imagecolorallocate($im,0,51,153);
			$aeraColor1[8]=imagecolorallocate($im,248,89,89);
			$aeraColor1[9]=imagecolorallocate($im,248,89,89);
			$aeraColor1[10]=imagecolorallocate($im,248,89,89);
            imagefill($im,0,0,$bgColor);
            imageline ( $im, 60, 0, 60, $height +28, $lineColor);
            imageline ( $im, 60, $height +28, $width + 60 -2 , $height +28,$lineColor);
			$fnt   =   "inc/fonts/simfang.ttf";   //11111
			$fnt1   =   "inc/fonts/STXINWEI.TTF";
             while($i < $num){
			 	// $alColor = imagecolorallocate($im,rand(0,255),rand(0,255),rand(0,255));  //随机色
                imagefilledrectangle ( $im, $i * ($tspace+$twidth) + 70, ceil($height-$height*($dataValue[$i]/($tempmun*40)))+30, $i * ($tspace+$twidth) + 40 + $twidth+30, $height +27, $aeraColor[$i]);
				imagefilledellipse ( $im,  $i * ($tspace+$twidth) + 70+($twidth/2), ceil($height-$height*($dataValue[$i]/($tempmun*40)))+30,$twidth, 18, $aeraColor1[$i] );
				//imagefilledrectangle ( $im, $i * ($tspace+$twidth) + 85, ceil($height-$height*($dataValue[$i]/($tempmun*40)))+30, $i * ($tspace+$twidth)+ $twidth+85, ceil($height-$height*($dataValue[$i]/($tempmun*40)))+40, $aeraColor[$i]);
			   // imagefilledrectangle ( $im, $i * ($tspace+$twidth) + 40, $height - $dataValue[$i], $i * ($tspace+$twidth) + 40 + $twidth, $height - 3, $tColor);
               // imagestring ( $im, 4, $i * ($tspace+$twidth) + $twidth/2 + 30, $height - $dataValue[$i], $dataName[$i]."(".$dataValue[$i].")", $lineColor);
				
				//imagestring ( $im, 4, $i * ($tspace+$twidth) + $twidth/2 + 50, ceil($height-$height*($dataValue[$i]/($tempmun*40)))+15, $dataValue[$i]."次", $lineColor);
				$str= iconv("GB2312","UTF-8","次");
				ImageTTFText( $im, 11, 0, $i * ($tspace+$twidth) + $twidth/2 + 50, ceil($height-$height*($dataValue[$i]/($tempmun*40)))+15, $lineColor, $fnt1,$dataValue[$i].$str);
				//$str   =   iconv("GB2312","UTF-8","欢迎光临");
				// ImageTTFText($im,   20,   0,   30,40,   $clr,   $fnt,   $str);    
				ImageTTFText( $im, 12,0, $i * ($tspace+$twidth) + $twidth/2+45, $height+45, $lineColor,$fnt1,$dataName[$i]);
                $i++;
             }
             while($j <= ($height/10)){
			 
                imagestring ( $im, 4, 15, $height - $j * 10 + 30, $j * $tempmun, $lineColor);
                $j = $j + 8;
             }
             while($k <= ($height/10)){
                 if($k != 0)
                imageline ( $im, 58, $height+30 - $k * 10, 62 , $height+30 - $k * 10,$lineColor);
                $k = $k + 8;
             }
            imagepng($im);
         }

header("content-type:image/png");
include('checkstate.php');
$id=$_GET['id'];
$sql="select languageid,counts from website where comid=$id";
		$result=mysql_query($sql);
		while($row=mysql_fetch_array($result)){			
			$counts=$row['counts'];
			$language=getlanguage($row['languageid']);
			$data[$language]=$counts;
		}
//$data=array("French" => 20772, "English" => 44414); 
//$data = array("Yahoo" => 100, "Google" => 260,"Microsoft" => 320,"IBM" => 250,"Sun System" => 150,"Inter" => 220);
createImage($data,50,25,400);

?>