PHP生成条形图的方法
本文实例讲述了服务器端编程语言(专业超文本预处理器的缩写)生成条形图的方法。分享给大家供大家参考。具体实现方法如下:
复制代码代码如下:php /为图表创建一个值数组。这些值//可以来自任何地方,开机自检、获取、数据库等$values=array(23,32,35,57,12,3,36,54,32,15,43,24,30);//现在我们得到数组中值的个数。这将//告诉我们绘制多少列$ columns=count($ values);//设置图形图像的高度和宽度$宽度=300$高度=200//设置每列之间的空间大小$ padding=5;//获取一列的宽度$ column _ width=$ width/$ columns;//设置图形颜色变量$im=imagecreate($width,$ height);$gray=imagecolorallocate ($im,0xcc,0xcc,0xcc);$ gray _ lite=image color allocate($ im,0xee,0xee,0xee);$ gray _ dark=image color allocate($ im,0x7f,0x7f,0x7f);$white=imagecolorallocate ($im,0xff,0xff,0x ff);//设置图形imagefilledrectangle的背景色($im,0,0,$width,$height,$ white);//计算我们要绘制的最大值$ max _ value=max($ values);//对($i=0)的列数组进行循环;一美元列;$i ) { //为每个值设置列高度$ column _ height=($ height/100)*($ values[$ I]/$ max _ value)* 100);//现在坐标$ x1=$ I * $ column _ width $ y1=$ height-$ column _ height;$ x2=($ I 1)* $ column _ width)-$ padding;$ y2=$ height//将列写在背景图像imagefilledrectangle上($im,$x1,$y1,$x2,$y2,$灰色);//这给了列一点三维(three dimension的缩写)效果imageline($im,$x1,$y1,$x1,$y2,$ gray _ lite);imageline($im,$x1,$y2,$x2,$y2,$ gray _ lite);imageline($im,$x2,$y1,$x2,$y2,$ gray _ dark);} //设置正确的巴布亚新几内亚头头(“内容类型:图像/png”);//将图片吐出另一端image png($ im);
运行效果如下图所示:
希望本文所述对大家的服务器端编程语言(专业超文本预处理器的缩写)程序设计有所帮助。
版权声明:PHP生成条形图的方法是由宝哥软件园云端程序自动收集整理而来。如果本文侵犯了你的权益,请联系本站底部QQ或者邮箱删除。