动网论坛,站长建站首选,国内使用量最多的论坛软件 动网论坛官方技术讨论区 站长工具 申请属于您自己的免费论坛
首页 | 新闻资讯 | 网站运营 | 网络编程 | 数据库 | 服务器 | 网页设计 | 图像媒体 | 网络应用 | 搜索优化 | 资源下载 | 动网主机 | DVBOX
    本站内  互联网 ASP论坛  ASP.Net论坛  PHP论坛
  
   PHP → 阅读文章

 PHP画图的程序

作者来源: 
阅读 数 79 人次 , 2006-3-29 4:08:00 


主要包括三个文件:
1、view.php是调用程序。
2、chart.php是用来生成图表的程序。
3、gbtoutf8.php是用来中文解码的(注:已解决中英文混合不能正常显示的问题)

1、view.php
<?
include("gbtoutf8.php");
?>
<html>
<head>
<title> </title>
<meta name="author" content="xiang li">
</head>
<?
/*此处数据可从数据库中取得*/
$astr = "it,pc,phone,sever,passport,software";
$asoft = "win2000,win98,office,foxmail,outlook";
$ahard = gb2utf8("地板,窗户,玻璃,桌子,灯管,植被");
$title1 = gb2utf8('2002年it维护report');
$title2 = gb2utf8('2002年软件维护report');
$title3 = gb2utf8('2002年固定资产report');
?>
<body>
<div align="center">
<table>
<tr>
<td><input type="image" src="./chart.php?astr=<?=$astr?>&title=<?=$title1?>"></td>
</tr>
<tr><td> </td></tr>
<tr>
<td><input type="image" src="./chart.php?astr=<?=$asoft?>&title=<?=$title2?>"></td>
</tr>
<tr><td> </td></tr>
<tr>
<td><input type="image" src="./chart.php?astr=<?=$ahard?>&title=<?=$title3?>"></td>
</tr>
</table></div>
</body>
</html>

2、chart.php
<?php
/*
* 功能:生成统计图表
* 程序员:wlxz
* 日期:2002-00-00
*/

header("content-type: image/png");
$im = imagecreate (350, 280);
$col_oth = imagecolorallocate($im, 0,0,0);
$col_orn = imagecolorallocate($im, 255,192,0);
$col_yel = imagecolorallocate($im, 255,255,0);
$col_red = imagecolorallocate($im, 255,0,0);
$col_grn = imagecolorallocate($im, 0,255,0);
$col_blu = imagecolorallocate($im, 0,0,255);
$col_wit = imagecolorallocate($im, 255,255,255);
$col_array = array($col_oth, $col_orn, $col_yel, $col_red, $col_grn, $col_blu);

$dot1 = 28;
$dot2 = 20;
$font="c:/winnt/fonts/simhei.ttf";
$astr = explode(",", trim($_get['astr']));
$title = trim($_get['title']);

imagettftext($im,18,0,100,50,$col_wit,$font,$title);//写标题

for($i=1;$i<count($col_array);$i++){
imagefilledrectangle($im,50*$i-$dot2,$dot1*$i,50*$i,200,$col_array[$i]);
imagerectangle($im,50*$i-$dot2,$dot1*$i,50*$i,200,$col_wit);
imagerectangle($im,50*$i-$dot2-1,$dot1*$i-1,50*$i+1,200,$col_wit);
imagettftext($im,14,270,50*$i-15,205,$col_wit,$font,$astr[$i-1]);

// imageline($im,50*$i-$dot2,$dot1*$i,50*$i-$dot2,200,$col_wit);
imageline($im,50*$i-$dot2,$dot1*$i,50*$i,$dot1*$i,$col_wit);
}
imagerectangle($im,10,10,300,200,$col_wit);
imagerectangle($im,11,11,301,201,$col_wit);

//右边百分比
for($i=1;$i<count($col_array);$i++){
imageline($im,300,$i*33,306,$i*33,$col_wit);
$str = (100-$i*5)."%";
imagettftext($im,14,0,315,$i*33+2,$col_wit,$font,$str);
}

imagepng($im);
imagedestroy($im);
?>

3.gbtoutf8.php
<?
/*
* 功能:把gb2312编码转换成utf-8的编码
* 程序员:wlxz
* 日期:2002-00-00
*/

function gb2utf8($gb){
if(!trim($gb))
return $gb;

$filename="gb2312.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)
{
$this=substr($gb,0,2);
$gb=substr($gb,2,strlen($gb));
$utf8=u2utf8(hexdec($codetable[hexdec(bin2hex($this))-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;
}


function gb2unicode($gb){
if(!trim($gb))
return $gb;

$filename="gb2312.txt";
$tmp=file($filename);
$codetable=array();

while(list($key,$value)=each($tmp))
$codetable[hexdec(substr($value,0,6))]=substr($value,9,4);
$utf="";
while($gb){
if (ord(substr($gb,0,1))>127){
$this=substr($gb,0,2);
$gb=substr($gb,2,strlen($gb));
$utf.="&#x".$codetable[hexdec(bin2hex($this))-0x8080].";";
}
else{
$gb=substr($gb,1,strlen($gb));
$utf.=substr($gb,0,1);
}
}
return $utf;
}
?>

 
 收藏本文  打印本文  论坛讨论  关闭窗口
· 上一篇:一个操作xml的类
· 下一篇:支持stmp认证、HTML格式邮件的类
· PHP 类
· PHP新手上路(一)
· 一个好用的UBB类
· PHP系统流量分析的程序
· 数组处理函数库


关于本站 | 联系我们 | 业务合作 | 客户案例 | 诚聘英才 | 广告合作 | 收藏本站
海口动网先锋网络科技有限公司版权所有
Copyright © 2000 - 2006 Cndw.Com
中华人民共和国电信与信息服务业务经营许可证编号 琼 ICP 020077