carpenter
(carpenter)
金牌会员
 
高级会员
UID 15303
精华
0
积分 1092
帖子 1073
金钱 1092 喜悦币
威望 0
人脉 0
阅读权限 70
注册 2002-7-17 来自 辽宁
状态 离线
|
[广告]: 代充Paypal帐号美元
终于解决的饼图的颜色问题
终于解决了颜色的问题,我觉得效果还可以
<? class pie_one { //**********************图形的属性******************* //创建图形 var $im; //图片名称 var $photo_name; //图片路径 var $photo_dir; //图形宽 var $photo_width=600; //图形高 var $photo_height=300; //**************************************************** //*********************颜色*************************** //定义颜色 var $black='000000'; var $white='FFFFFF'; var $yellow='FF6600'; var $red='FF0000'; var $green='99CC00'; var $blue='0000CC'; var $gray='CCCCCC'; var $color=array(1=>'9999FF',2=>'993366',3=>'FFFFCC',4=>'CCFFFF',5=>'660066',6=>'FF9999',7=>'CCCCFF',8=>'000099',9=>'99CC00',10=>'FF6600',11=>'CC99FF',12=>'990099',13=>'990000',14=>'009999',15=>'3366FF',16=>'00CCFF',17=>'CCFFFF',18=>'99CC00');
//**************************************************** //*********************字体*************************** //字体 var $font="simhei.ttf"; //字体目录 var $font_dir="c:/winnt/fonts/"; //***************************************************** //*********************标题**************************** //标题在顶部下面的距离 var $topic_under=30; //标题距离左边的距离 var $topic_left=20; //标题内容 var $topic_note="广东发展银行大连分行"; //标题字体大小 var $topic_note_size=20; //标题颜色 var $topic_note_color='0000CC'; //标题角度 var $topic_note_angle=0; //***************************************************** //**********************饼图的属性********************* //饼图中心距离顶上的距离 var $pie_center_top=150; //饼图中心距离左边的距离 var $pie_center_left=200; //饼图X轴半径长度 var $pie_x_lenght=150; //饼图Y轴半径长度 var $pie_y_lenght=100; //饼图分几份 var $pie_num; //饼图的颜色 var $pie_color; //饼图数据 var $pie_data01; //饼图指标 var $pie_data02; //饼图阴影高度 var $pie_shadow_height=30; //饼图阴影颜色 var $pie_shadow_color='CCCCCC'; //饼图注释字体大小 var $pie_note_size=3; //饼图注释字体颜色 var $pie_note_color='0000CC'; //饼图注释高度调整 var $pie_note_height=0; //饼图注释向左调整 var $pie_note_left=15; //********************************************************************************** //**********************图例注释的属性************************************************** //图例距左边距离 var $note_left=410; //图例距顶上距离 var $note_top=30; //图例的大小 var $note_lenght=10; //图例之间距离 var $note_space=17; //图例文字型号 var $note_size=12; //图例文字角度 var $note_angle=0; //********************************************************************************** //创建图形 function pie_one() { $this->im=imagecreate($this->photo_width,$this->photo_height); $this->black = ImageColorAllocate($this->im,hexdec(substr($this->black,0,2)),hexdec(substr($this->black,2,2)),hexdec(substr($this->black,4,2))); $this->white = ImageColorAllocate($this->im,hexdec(substr($this->white,0,2)),hexdec(substr($this->white,2,2)),hexdec(substr($this->white,4,2))); $this->yellow = ImageColorAllocate($this->im,hexdec(substr($this->yellow,0,2)),hexdec(substr($this->yellow,2,2)),hexdec(substr($this->yellow,4,2))); $this->red = ImageColorAllocate($this->im,hexdec(substr($this->red,0,2)),hexdec(substr($this->red,2,2)),hexdec(substr($this->red,4,2))); $this->green = ImageColorAllocate($this->im,hexdec(substr($this->green,0,2)),hexdec(substr($this->green,2,2)),hexdec(substr($this->green,4,2))); $this->blue = ImageColorAllocate($this->im,hexdec(substr($this->blue,0,2)),hexdec(substr($this->blue,2,2)),hexdec(substr($this->blue,4,2))); $this->gray = ImageColorAllocate($this->im,hexdec(substr($this->gray,0,2)),hexdec(substr($this->gray,2,2)),hexdec(substr($this->gray,4,2))); for($i=1;$i<=19;$i++) { $this->color[$i] = ImageColorAllocate($this->im,hexdec(substr($this->color[$i],0,2)),hexdec(substr($this->color[$i],2,2)),hexdec(substr($this->color[$i],4,2))); } $this->topic_note_color = ImageColorAllocate($this->im,hexdec(substr($this->topic_note_color,0,2)),hexdec(substr($this->topic_note_color,2,2)),hexdec(substr($this->topic_note_color,4,2))); $this->pie_shadow_color = ImageColorAllocate($this->im,hexdec(substr($this->pie_shadow_color,0,2)),hexdec(substr($this->pie_shadow_color,2,2)),hexdec(substr($this->pie_shadow_color,4,2))); $this->pie_note_color = ImageColorAllocate($this->im,hexdec(substr($this->pie_note_color,0,2)),hexdec(substr($this->pie_note_color,2,2)),hexdec(substr($this->pie_note_color,4,2))); } function create() { //使图形变成白色 imagefill($this->im,0,0,$this->white); //为图形增加边框 imagerectangle($this->im,0,0,$this->photo_width-1,$this->photo_height-1,$this->black); //标题 $this->topic(); $this->pie(); $this->end(); } //写标题 function topic() { ImageTTFText($this->im,$this->topic_note_size,$this->topic_note_angle,$this->topic_left,$this->topic_under,$this->topic_note_color, $this->font_dir.$this->font,$this->gb2utf8($this->topic_note)); } //划饼图 function pie() { //划椭圆 imagearc($this->im,$this->pie_center_left,$this->pie_center_top,2*$this->pie_x_lenght,2*$this->pie_y_lenght, 0, 360,$this->black); //划扇形 if($this->pie_num > 0) { $subdata01=0; for($i=1;$i<=$this->pie_num;$i++) { $subdata01=$subdata01+$this->pie_data01[$i]; } imageline($this->im,$this->pie_center_left,$this->pie_center_top,$this->pie_center_left+$this->pie_x_lenght,$this->pie_center_top,$this->black); for($i=1;$i<=$this->pie_num;$i++) { $subdata02=$subdata02+$this->pie_data01[$i]; //计算填充点的角度 $del=360*(2*$subdata02-$this->pie_data01[$i])/(2*$subdata01); if($i!=$this->pie_num) { imageline($this->im,$this->pie_center_left,$this->pie_center_top,$this->pie_center_left+round($this->pie_x_lenght*cos(deg2rad((360*$subdata02)/$subdata01))),$this->pie_center_top+round($this->pie_y_lenght*sin(deg2rad((360*$subdata02)/$subdata01))),$this->black); } //填充 imagefill($this->im,$this->pie_center_left+round($this->pie_x_lenght*cos(deg2rad($del))/2),$this->pie_center_top+round($this->pie_y_lenght*sin(deg2rad($del))/2),$this->color[$i]); //标注 //imagerectangle($this->im,$this->pie_center_left+round($this->pie_x_lenght*cos(deg2rad($del))),$this->pie_center_top+round($this->pie_y_lenght*sin(deg2rad($del))),$this->pie_center_left+round($this->pie_x_lenght*cos(deg2rad($del)))+35,$this->pie_center_top+round($this->pie_y_lenght*sin(deg2rad($del)))+10,$this->black); imagestring($this->im,$this->pie_note_size,$this->pie_center_left+round($this->pie_x_lenght*cos(deg2rad($del))*1.2)-$this->pie_note_left,$this->pie_center_top+round($this->pie_y_lenght*sin(deg2rad($del))*1.2)-$this->pie_note_height,number_format(100*$this->pie_data01[$i]/$subdata01,2,'.','').'%',$this->pie_note_color); //说明 imagerectangle($this->im,$this->note_left,$this->note_top+($i-1)*$this->note_space,$this->note_left+$this->note_lenght,$this->note_top+$this->note_lenght+($i-1)*$this->note_space,$this->black); imagefill($this->im,$this->note_left+1,$this->note_top+($i-1)*$this->note_space+1,$this->color[$i]); $note_txt=$this->pie_data02[$i]; $note_txt=number_format(100*$this->pie_data01[$i]/$subdata01,2,'.','').'% '.$this->gb2utf8($note_txt).' '.$this->pie_data01[$i]; ImageTTFText($this->im,$this->note_size,$this->note_angle,$this->note_left+20,$this->note_top+($i-1)*$this->note_space+$this->note_lenght,$this->note_color, $this->font_dir.$this->font, $note_txt); } } //饼图阴影 if($this->pie_shadow_height > 0) { imageline($this->im,$this->pie_center_left-$this->pie_x_lenght,$this->pie_center_top,$this->pie_center_left-$this->pie_x_lenght,$this->pie_center_top+$this->pie_shadow_height,$this->black); imageline($this->im,$this->pie_center_left+$this->pie_x_lenght,$this->pie_center_top,$this->pie_center_left+$this->pie_x_lenght,$this->pie_center_top+$this->pie_shadow_height,$this->black); imagearc($this->im,$this->pie_center_left,$this->pie_center_top+$this->pie_shadow_height,2*$this->pie_x_lenght,2*$this->pie_y_lenght, 0, 180,$this->black); if($this->pie_shadow_height > 1) { imagefill($this->im,$this->pie_center_left,$this->pie_center_top+$this->pie_y_lenght+$this->pie_shadow_height-1,$this->pie_shadow_color); } } } //结束图形 function end() { if($this->photo_dir.$this->photo_name=="") { Imagepng($this->im); } else { Imagepng($this->im,$this->photo_dir.$this->photo_name); } ImageDestroy($this->im); } //两个转换中文代码的函数 function gb2utf8($gb) { if(!trim($gb)) return $gb; $filename="??????.txt"; $tmp=file($filename); $codetable=array(); while(list($key,$value)=each($tmp)) $codetable[hexdec(substr($value,0,6))]=substr($value,7,6); $ret=""; $utf8=""; while($gb) { if (ord(substr($gb,0,1))>127) { $thiss=substr($gb,0,2); $gb=substr($gb,2,strlen($gb)); $utf8=$this->u2utf8(hexdec($codetable[hexdec(bin2hex($thiss))-0x8080])); for($i=0;$i<strlen($utf8);$i+=3) $ret.=chr(substr($utf8,$i,3)); } else { $ret.=substr($gb,0,1); $gb=substr($gb,1,strlen($gb)); } } return $ret; } // function u2utf8($c) { for($i=0;$i<count($c);$i++) $str=""; if ($c < 0x80) { $str.=$c; } else if ($c < 0x800) { $str.=(0xC0 | $c>>6); $str.=(0x80 | $c & 0x3F); } else if ($c < 0x10000) { $str.=(0xE0 | $c>>12); $str.=(0x80 | $c>>6 & 0x3F); $str.=(0x80 | $c & 0x3F); } else if ($c < 0x200000) { $str.=(0xF0 | $c>>18); $str.=(0x80 | $c>>12 & 0x3F); $str.=(0x80 | $c>>6 & 0x3F); $str.=(0x80 | $c & 0x3F); } return $str; } } $tt=new pie_one;
$tt->topic_note="测试"; $tt->pie_num=16; $tt->pie_data01=array(1=>10,2=>10,3=>10,4=>10,5=>10,6=>10,7=>10,8=>10,9=>10,10=>10,11=>10,12=>10,13=>10,14=>10,15=>10,16=>10,17=>10); //$tt->pie_data02=array(1=>'指标1',2=>'指标1',3=>'指标1',4=>'指标1',5=>'指标1',6=>'指标1',7=>'指标1',8=>'指标1',9=>'指标1',10=>'指标1',11=>'指标1',12=>'指标1',13=>'指标1',14=>'指标1',15=>'指标1',16=>'指标1',17=>'指标1'); $tt->create(); ?>
|
|