选择显示字体大小

给你一个画饼图的,画直方图直接用img控制其宽高就可实现吧


   //调用方法:<image src=&quot;chart.php&quot;>
//chart.php为本文文件名

<?

/*
把角度转换为弧度
*/
function radians (&#36;degrees)
{
return(&#36;degrees * (pi()/180.0));
}
/*
** 取得在圆心为(0,0)圆上 x,y点的值
*/
function circle_point(&#36;degrees, &#36;diameter)
{
&#36;x = cos(radians(&#36;degrees)) * (&#36;diameter/2);
&#36;y = sin(radians(&#36;degrees)) * (&#36;diameter/2);

return (array(&#36;x, &#36;y));
}
// 填充图表的参数
&#36;chartdiameter = 200; //图表直径
&#36;chartfont = 2; //图表字体
&#36;chartfontheight = imagefontheight(&#36;chartfont);//图表字体的大小

   require(&#39;mysql.php3&#39;);
   &#36;sql=new mysql_class;
   &#36;sql->create(&#39;star&#39;);
   &#36;sql->query(&quot;select * from serch where answer=&#39;富士通常昊 九段&#39;&quot;);
   &#36;record1=&#36;sql->rows;
   &#36;sql->query(&quot;select * from serch where answer=&#39;富士通曹薰铉 九段&#39;&quot;);
   &#36;record2=&#36;sql->rows;          

&#36;chartdata = array( &#36;record1,&#36;record2);//用于生成图表的数据,可通过数据库来取得来确定
//&#36;chartlabel = array(&quot;常昊九段&quot;, &quot;曹薰铉九段&quot;); //数据对应的名称

//确定图形的大小
&#36;chartwidth = &#36;chartdiameter + 20;
&#36;chartheight = &#36;chartdiameter + 20 +
((&#36;chartfontheight + 2) * count(&#36;chartdata));

//确定统计的总数
for(&#36;index = 0; &#36;index < count(&#36;chartdata); &#36;index++)
{
&#36;charttotal += &#36;chartdata[&#36;index];
}

&#36;chartcenterx = &#36;chartdiameter/2 + 10;
&#36;chartcentery = &#36;chartdiameter/2 + 10;


//生成空白图形
&#36;image = imagecreate(&#36;chartwidth, &#36;chartheight);

//分配颜色
&#36;colorbody = imagecolorallocate(&#36;image, 0xe4, 0xe6, 0xd1);
&#36;colorborder = imagecolorallocate(&#36;image, 0x00, 0x00, 0x00);
&#36;colortext = imagecolorallocate(&#36;image, 0x00, 0x00, 0x00);

&#36;colorslice[] = imagecolorallocate(&#36;image, 0xff, 0x00, 0x00);
&#36;colorslice[] = imagecolorallocate(&#36;image, 0x00, 0x00, 0xff);


//填充背境
imagefill(&#36;image, 0, 0, &#36;colorbody);


/*
** 画每一个扇形
*/
&#36;degrees = 0;
for(&#36;index = 0; &#36;index < count(&#36;chartdata); &#36;index++)
{
&#36;startdegrees = round(&#36;degrees);
&#36;degrees += ((&#36;chartdata[&#36;index]/&#36;charttotal)*360);
&#36;enddegrees = round(&#36;degrees);

&#36;currentcolor = &#36;colorslice[&#36;index%(count(&#36;colorslice))];

//画图f
imagearc(&#36;image,&#36;chartcenterx,&#36;chartcentery,&#36;chartdiameter,
&#36;chartdiameter,&#36;startdegrees,&#36;enddegrees, &#36;currentcolor);

//画直线
list(&#36;arcx, &#36;arcy) = circle_point(&#36;startdegrees, &#36;chartdiameter);
imageline(&#36;image,&#36;chartcenterx,&#36;chartcentery,floor(&#36;chartcenterx + &#36;arcx),
floor(&#36;chartcentery + &#36;arcy),&#36;currentcolor);
//画直线
list(&#36;arcx, &#36;arcy) = circle_point(&#36;enddegrees, &#36;chartdiameter);
imageline(&#36;image,&#36;chartcenterx,&#36;chartcentery,ceil(&#36;chartcenterx + &#36;arcx),
ceil(&#36;chartcentery + &#36;arcy),&#36;currentcolor);

//填充扇形
&#36;midpoint = round(((&#36;enddegrees - &#36;startdegrees)/2) + &#36;startdegrees);
list(&#36;arcx, &#36;arcy) = circle_point(&#36;midpoint, &#36;chartdiameter/2);
imagefilltoborder(&#36;image,floor(&#36;chartcenterx + &#36;arcx),floor(&#36;chartcentery + &#36;arcy),
&#36;currentcolor,&#36;currentcolor);
}

//画边框
imagearc(&#36;image,
&#36;chartcenterx,
&#36;chartcentery,
&#36;chartdiameter,
&#36;chartdiameter,
0,
180,
&#36;colorborder);

imagearc(&#36;image,
&#36;chartcenterx,
&#36;chartcentery,
&#36;chartdiameter,
&#36;chartdiameter,
180,
360,
&#36;colorborder);


imagearc(&#36;image,
&#36;chartcenterx,
&#36;chartcentery,
&#36;chartdiameter+7,
&#36;chartdiameter+7,
0,
180,
&#36;colorborder);

imagearc(&#36;image,
&#36;chartcenterx,
&#36;chartcentery,
&#36;chartdiameter+7,
&#36;chartdiameter+7,
180,
360,
&#36;colorborder);


imagefilltoborder(&#36;image,
floor(&#36;chartcenterx + (&#36;chartdiameter/2) + 2),
&#36;chartcentery,
&#36;colorborder,
&#36;colorborder);


//画图例
for(&#36;index = 0; &#36;index < count(&#36;chartdata); &#36;index++)
{
&#36;currentcolor = &#36;colorslice[&#36;index%(count(&#36;colorslice))];
&#36;liney = &#36;chartdiameter + 20 + (&#36;index*(&#36;chartfontheight+2));

//draw color box
imagerectangle(&#36;image,
10,
&#36;liney,
10 + &#36;chartfontheight,
&#36;liney+&#36;chartfontheight,
&#36;colorborder);

imagefilltoborder(&#36;image,
12,
&#36;liney + 2,
&#36;colorborder,
&#36;currentcolor);

//画标签
imagestring(&#36;image,
&#36;chartfont,
20 + &#36;chartfontheight,
&#36;liney,
&quot;&#36;chartdata[&#36;index]&quot;,
&#36;colortext);
}

//到此脚本 已经生了一幅图像的,现在需要的是把它发到浏览器上,重要的一点是要将标头发给浏览器,让它知道是一个gif文件。不然的话你只能看到一堆奇怪的乱码

header(&quot;content-type: image/gif&quot;);
//输出生成的图片
imagegif(&#36;image);
?>


 


关键字 本文所属关键字

相关 与本文相关文章

分类 所有文章关键字导航

源码编程相关

Java   Asp   PHP   .Net   XML   C/C++   CGI   VB   Jsp   J2ee   J2se   J2me   EJB   Servlet   Tomcat   Resin   Struts   Weblogic   Eclipse   ANT   GUI   JMS   Web servise   IDEA   Webphere   Hibernate   Spring   Jboss   Applet   Swing   Socket   Javamail   Perl   Ajax   P2P   安全   模式   框架   测试   开源   游戏

SQL数据库相关

My-SQL   Ms-SQL   Access   DB2   Oracle   Sybase   SQLserver   索引   存储过程   加密   数据库   分页   视图  

手机无线相关

3G   Wap   CDMA   GRPS   GSM   IVR   彩信   短信   无线   增值业务

网页设计制作相关

HTML   CSS   网页配色   网页特效   Javascript   VBscript   Dreamweaver   Frontpage   JS   Web   网站设计

网站建设推广相关

建站经验   网站优化   网站排名   推广   Alexa

操作系统/服务器相关

Windows XP   Windows 2000   Windows 2003   Windows Me   Windows 9.x   Linux   UNIX   注册表   操作系统   服务器   应用服务器

图形图像多媒体相关

Photoshop   Fireworks   Flash   Coreldraw   Illustrator   Freehand   Photoimpact   多媒体   图形图像

标准 网站致力的规范

Valid CSS!

无不良内容,无不良广告,无恶意代码

Valid XHTML 1.0 Transitional

creativecommons