php 报表开发
?什么是报表
报表( 报: 报告 表: 表格 图表)
所谓报表就是,以表格或者是图表的方式 显示报告数据.
演示了jpgrapf的一个案例
?php绘图的坐标系统
?php绘图技术
1.php绘图的基本原理和步骤
?创建画布
?绘制需要的各种图形(圆,直线,矩形,弧线,扇形...)
?输出图像到网页,也可以另存
?销毁该图片(释放内存)
? 目前网站开发常见的图片格式有 gif jpg/jpeg png bmp ....
总结:
?gif 图片压缩率高,但是只能显示256色,可能造成颜色丢失,可以显示动画
?jpg/jpeg 图片的压缩率高(有损压缩),可以用较小的文件来显示,网页上用的比较图
?png , 该格式综合了gif 和jpg的优势,缺点是不能显示动画
怎么选择:
?php绘图技术快速入门
前提 : 首先请大家确认你的 gd库启用 php.ini
;启用图像库
extension=php_gd2.dll
记住,需要重启启动apache
image1.php案例:
showAll.php
showVote.php (最核心的)<?php // content="text/plain; charset=utf-8"require_once ('jpgraph/jpgraph.php');require_once ('jpgraph/jpgraph_bar.php');//$datay1=array(13,8,119,7,17,6);//$datay2=array(0,0,0,0,0,0);//$datay1=array(13,8,11);//$datay2=array(0,0,0);// Create the graph.$graph = new Graph(350,250);$graph->SetScale('textlin');$graph->SetMarginColor('silver');// Setup title/*$str="";$id=$_REQUEST['id']; if($id==1){$str="支持布什的统计情况(万)";}else if($id==2){$str="支持奥巴马的统计情况(万)";}*///从数据库$id=$_REQUEST["id"];//组织sql$sql="select * from elector where electorId=$id order by voteMonth";$conn=mysql_connect("localhost","root","root") or die("连接失败".mysql_error());mysql_select_db("test",$conn) or die(mysql_error());mysql_query("set names gbk") or die(mysql_error());$res=mysql_query($sql,$conn) or die(mysql_error());$datay1=array();$datay2=array();$i=0;$title="";while($row=mysql_fetch_array($res)){$datay1[$i]=$row[2];$datay2[$i]=0;if($i==0){$title="支持".$row[1]."情况统计图";}$i++;}mysql_free_result($res);mysql_close($conn);$graph->title->Set($title);$graph->title->setFont(FF_SIMSUN,FS_BOLD,14);// Create the first bar$bplot = new BarPlot($datay1);$bplot->SetFillGradient('AntiqueWhite2','AntiqueWhite4:0.8',GRAD_VERT);$bplot->SetColor('darkred');// Create the second bar$bplot2 = new BarPlot($datay2);$bplot2->SetFillGradient('olivedrab1','olivedrab4',GRAD_VERT);$bplot2->SetColor('darkgreen');// And join them in an accumulated bar$accbplot = new AccBarPlot(array($bplot,$bplot2));$graph->Add($accbplot);$graph->Stroke();?>