破釜沉舟论坛 » WEB 开发 » 请帮忙,为什么我的用php做的饼状图是乱码??急!!

2006-4-6 14:30 rabbit
请帮忙,为什么我的用php做的饼状图是乱码??急!!

  代码如下:()
<?php
include "gb2utf8.php";




//公用函数

//把角度转换为弧度
function deg2Arc($degrees) {
return($degrees * (pi()/180.0));
}

//RGB
function getRGB($color){
  $R=($color>>16) & 0xff;
  $G=($color>>8) & 0xff;
  $B=($color) & 0xff;
  return (array($R,$G,$B));
}

// 取得在椭圆心为(0,0)的椭圆上 x,y点的值
function pie_point($deg,$va,$vb){
$x= cos(deg2Arc($deg)) * $va;
$y= sin(deg2Arc($deg)) * $vb;
return (array($x, $y));
}


//3D饼图类

class Pie3d{

var $a; //椭圆长半轴
var $b; //椭圆短半轴
var $DataArray;  //每个扇形的数据
var $ColorArray; //每个扇形的颜色 要求按照十六进制书写但前面不加0x
var $ChartLabel;
//为边缘及阴影为黑色

function Pie3d($pa=100,$pb=60,$sData="100,200,", $sColor="ee00ff,dd0000,cccccc,ccff00,00ccff,cceeff",$stext="aa,bb")
{   //$sData=array(100,200,300,400,500);
   $this->a=120;
   $this->b=80;
    //$dwdm='1022022207';
             include "envsksjk.ini";
             $connect_code=Ora_Logon($user,$passwd);
             if ($connect_code < 0) {
              echo("Could not connect to Oracle.\n");
              exit;
             }
             $cursor = Ora_Open($connect_code);
             Ora_CommitOff($connect_code);
             $table_name="dzhys";
             $sql="select sum(yxcl) from $table_name where to_char(rq,'YYYYMMDD') like '200603' group by yslb";
             Ora_Parse($cursor, $sql);
             ora_exec($cursor);
             $err=Ora_Fetch($cursor);
             $i=0;
             $counti=0;
             while($err==1){
             $this->DataArray[$i]=Ora_GetColumn($cursor,0);
             //$wh[$i]=trim(Ora_GetColumn($cursor,1));
             $i++;
             $counti++;
             $err = Ora_Fetch($cursor);
             }
             /*
             for ($i=0;$i<$counti;$i++){
             $sql="select dmmc from flr4 where dm='$wh[$i]'";
             Ora_Parse($cursor, $sql);
             ora_exec($cursor);
             Ora_Fetch($cursor);  
             $this->ChartLabel[$i]=Ora_GetColumn($cursor,0);
              }*/
             $this->ColorArray=split(",",$sColor);
}
function  DrawPie(){
   $image=imagecreate($this->a*2+80,$this->b*2+120);
   $PieCenterX=$this->a+10;
   $PieCenterY=$this->b+10;
   $DoubleA=$this->a*2;
   $DoubleB=$this->b*2;
   list($R,$G,$B)=getRGB(0);
   $colorBorder=imagecolorallocate($image,$R,$G,$B);
   $DataNumber=count($this->DataArray);
    
   //$DataTotal
   for($i=0;$i<$DataNumber;$i++)      $DataTotal+=$this->DataArray[$i]; //算出数据和
    
   //填充背境
   imagefill($image, 0, 0, imagecolorallocate($image, 0xFF, 0xFF, 0xFF));

   /*
   ** 画每一个扇形
   */
   $Degrees = 0;
   for($i = 0; $i < $DataNumber; $i++){
       $StartDegrees = round($Degrees);
       $Degrees += (($this->DataArray[$i]/$DataTotal)*360);
       $EndDegrees = round($Degrees);
       $percent[$i] = number_format($this->DataArray[$i]/$DataTotal*100, 1);  
       list($R,$G,$B)=getRGB(hexdec($this->ColorArray[$i]));
       $CurrentColor=imagecolorallocate($image,$R,$G,$B);
       if ($R>60 and $R<256)            $R=$R-60;
       if ($G>60 and $G<256)            $G=$G-60;
       if ($B>60 and $B<256)            $B=$B-60;
       $CurrentDarkColor=imagecolorallocate($image,$R,$G,$B);
       //画扇形弧
       imagearc($image,$PieCenterX,$PieCenterY,$DoubleA,$DoubleB,$StartDegrees,$EndDegrees,$CurrentColor);
       //画直线
       list($ArcX, $ArcY) = pie_point($StartDegrees , $this->a , $this->b);
       imageline($image,$PieCenterX,$PieCenterY,floor($PieCenterX + $ArcX),floor($PieCenterY + $ArcY),$CurrentColor);
       //画直线
       list($ArcX, $ArcY) = pie_point($EndDegrees,$this->a , $this->b);
       imageline($image,$PieCenterX,$PieCenterY,ceil($PieCenterX + $ArcX),ceil($PieCenterY + $ArcY),$CurrentColor);
       //填充扇形
       $MidPoint = round((($EndDegrees - $StartDegrees)/2) + $StartDegrees);
       list($ArcX, $ArcY) = Pie_point($MidPoint, $this->a*3/4 , $this->b*3/4);
       
       imagefilltoborder($image,floor($PieCenterX + $ArcX),floor($PieCenterY + $ArcY), $CurrentColor,$CurrentColor);
       imagestringhz16j($image,2,floor($PieCenterX + $ArcX-30),floor($PieCenterY + $ArcY-5),$this->ChartLabel[$i],$colorBorder);

       //画阴影
       if ($StartDegrees>=0 and $StartDegrees<=180){
          if($EndDegrees<=180){     
              for($k = 1; $k < 15; $k++)
               imagearc($image,$PieCenterX, $PieCenterY+$k,$DoubleA, $DoubleB, $StartDegrees, $EndDegrees, $CurrentDarkColor);
          }else{
              for($k = 1; $k < 15; $k++)
               imagearc($image,$PieCenterX, $PieCenterY+$k,$DoubleA, $DoubleB, $StartDegrees, 180, $CurrentDarkColor);
          }

       }
  }
    $colorText = imagecolorallocate($image, 0,0,0);
     for($i = 0; $i < $DataNumber; $i++){
             list($R,$G,$B)=getRGB(hexdec($this->ColorArray[$i]));  
             $CurrentColor=imagecolorallocate($image,$R,$G,$B);
             $LineY = $this->a+70+($i*16);
             //draw color box
             imagerectangle($image,
             10,
             $LineY,
             16 + 8,
             $LineY+8+2,
             $colorBorder);
             imagefilltoborder($image,
             12,
             $LineY + 2,
             $colorBorder,
             $CurrentColor);
             //画标签
             //$str=gb2utf8($this->ChartLabel[$i]);
             imagestringhz16j($image,
             3,
             20 + 5,
             $LineY,
             $this->ChartLabel[$i].":".$this->DataArray[$i]."人占".$percent[$i]."%",
             $colorText); }
       
  header("Content-type: image/gif");
   imagegif($image);
   imagedestroy($image);
}//End drawPie()
}//End class
//实现
$objp = new Pie3d();
$objp->DrawPie();
?>

2006-4-7 08:39 rabbit
怎样把gb2312转换成UTF-8?

2006-4-7 11:42 木舟
[code]
<?
$content=iconv("UTF-8","GB2312",$content);
// $content 为转换成utf8后的结果.
echo   $content;
?>
[/code]

页: [1]


Powered by Discuz! Archiver 5.5.0  © 2001-2006 Comsenz Inc.