php报表开发Word格式.docx
《php报表开发Word格式.docx》由会员分享,可在线阅读,更多相关《php报表开发Word格式.docx(11页珍藏版)》请在冰点文库上搜索。
5//imageellipse($im,20,20,20,20,$red);
6//直线
7//imageline($im,0,0,400,300,$red);
8//矩形
9//imagerectangle($im,2,2,40,50,$red);
10//填充矩形
11//imagefilledrectangle($im,2,2,40,50,$red);
12//弧线
13//imagearc($im,100,100,50,50,180,270,$red);
14//扇形
15//imagefilledarc($im,100,100,80,50,180,270,$red,IMG_ARC_PIE);
16
17//拷贝图片到画布
18//1.加载源图片
19//$srcImage=imagecreatefromgif("
2.GIF"
);
20//这里我们可以使用一个getimagesize()
21//$srcImageInfo=getimagesize("
22
23//拷贝源图片到目标画布
24//imagecopy($im,$srcImage,0,0,0,0,$srcImageInfo[0],$srcImageInfo[1]);
25
26//写字
27$str="
hello,world,中文"
28//imagestring($im,5,0,0,"
$red);
29//在字体库中去找中文
30imagettftext($im,20,10,50,50,$red,"
simhei.ttf"
$str);
31header("
content-type:
image/png"
32imagepng($im);
33imagedestory($im);
34?
>
综合案例:
(综合使用)
代码:
35<
36
37
38//分析思路(先画出扇形)
39
40
41//1.画布
42$im=imagecreatetruecolor(400,300);
43
44//默认是黑色背景(一会告诉大家怎么修改)
45$white=imagecolorallocate($im,255,255,255);
46imagefill($im,0,0,$white);
47
48//2.画出扇形
49//创建三个颜色
50$red=imagecolorallocate($im,254,0,0);
51$darkred=imagecolorallocate($im,144,0,0);
52$blue=imagecolorallocate($im,0,0,128);
53$darkblue=imagecolorallocate($im,0,0,80);
54$gary=imagecolorallocate($im,192,192,192);
55$darkgary=imagecolorallocate($im,144,144,144);
56
57for($i=60;
$i>
=50;
$i--){
58imagefilledarc($im,100,$i,100,50,0,35,$darkblue,IMG_ARC_PIE);
59imagefilledarc($im,100,$i,100,50,35,75,$darkgary,IMG_ARC_PIE);
60imagefilledarc($im,100,$i,100,50,75,360,$darkred,IMG_ARC_PIE);
61}
62
63//在上面加盖
64imagefilledarc($im,100,50,100,50,0,35,$blue,IMG_ARC_PIE);
65imagefilledarc($im,100,50,100,50,35,75,$gary,IMG_ARC_PIE);
66imagefilledarc($im,100,50,100,50,75,360,$red,IMG_ARC_PIE);
67
68//输出图片
69header("
70imagepng($im);
71imagedestory($im);
72
73//有兴趣的同学可以将其封装成一个函数.
74
75
76?
u思考
如果每次都必须自己去画,这样的图,是不是很麻烦,有没有现成可以用于做图表开发的库
->
jpgrapf
ujpgraph的介绍
jpgraph的安装和配置
1.下载官网
2.解压(先拷贝到htdocs目录)
3.配置完毕使用(就是把emample目录的其它文件剪切到emamlpe文件夹内,注意要新建一个文件夹名字一定是jpgraph)
4.测试
ujpgraph的实际使用案例(网名调查统计图
完成案例示意图如下:
数据库和数据
--参加选举人的表
createtableelector(
electorIdint,
namevarchar(64),
voteNumsint,
voteMonthint);
insertintoelectorvalues(1,'
布什'
10,1);
12,2);
34,3);
insertintoelectorvalues(2,'
奥巴马'
34,1);
30,2);
12,3);
30,4);
☞如果希望吧jpgraph的图表嵌入到其它的php文件中,可以使用<
img/>
静态显示数据(没有实时的取数据)
实时取数据(动态更新)
vote.php
77<
html>
78<
head>
79<
title>
请投票<
/title>
80<
scriptlanguage="
javascript"
81functionlook(){
82window.location.href="
showAll.php"
83}
84<
/script>
85<
metahttp-equiv="
content-type"
content="
text/html;
charset=utf-8"
/>
86<
/head>
87<
formaction="
"
method="
88<
table>
89<
tr>
<
td>
/td>
/tr>
90<
91<
inputtype="
radio"
name="
vote"
value="
1"
布什
92<
2"
奥巴马
93<
submit"
投票"
94<
95<
/table>
96<
/form>
97<
98<
99<
button"
onclick="
look();
查看投票统计图表"
100<
101<
102<
/html>
showAll.php
103<
104<
105<
显示<
106<
107<
108<
body>
109<
h1>
显示网民支持情况<
/h1>
110<
imgsrc="
showVote.php?
id=1"
/>
111<
showvote.php?
id=2"
112<
/body>
113<
showVote.php(最核心的)
114<
php//content="
text/plain;
charset=utf-8"
115require_once('
jpgraph/jpgraph.php'
116require_once('
jpgraph/jpgraph_bar.php'
117
118//$datay1=array(13,8,119,7,17,6);
119//$datay2=array(0,0,0,0,0,0);
120
121//$datay1=array(13,8,11);
122//$datay2=array(0,0,0);
123//Createthegraph.
124$graph=newGraph(350,250);
125$graph->
SetScale('
textlin'
126$graph->
SetMarginColor('
silver'
127
128
129//Setuptitle
130/*$str="
131$id=$_REQUEST['
id'
];
132if($id==1){
133$str="
支持布什的统计情况(万)"
134}
135elseif($id==2){
136$str="
支持奥巴马的统计情况(万)"
137}*/
138
139//从数据库
140
141$id=$_REQUEST["
id"
142//组织sql
143$sql="
select*fromelectorwhereelectorId=$idorderbyvoteMonth"
144
145
146
147$conn=mysql_connect("
localhost"
"
root"
)ordie("
连接失败"
.mysql_error());
148mysql_select_db("
test"
$conn)ordie(mysql_error());
149mysql_query("
setnamesgbk"
)ordie(mysql_error());
150$res=mysql_query($sql,$conn)ordie(mysql_error());
151
152$datay1=array();
153$datay2=array();
154$i=0;
155$title="
156while($row=mysql_fetch_array($res))
157{
158$datay1[$i]=$row[2];
159$datay2[$i]=0;
160
161if($i==0){
162$title="
支持"
.$row[1]."
情况统计图"
163}
164$i++;
165}
166mysql_free_result($res);
167mysql_close($conn);
168
169
170$graph->
title->
Set($title);
171$graph->
setFont(FF_SIMSUN,FS_BOLD,14);
172//Createthefirstbar
173$bplot=newBarPlot($datay1);
174$bplot->
SetFillGradient('
AntiqueWhite2'
'
AntiqueWhite4:
0.8'
GRAD_VERT);
175$bplot->
SetColor('
darkred'
176
177//Createthesecondbar
178$bplot2=newBarPlot($datay2);
179$bplot2->
olivedrab1'
olivedrab4'
180$bplot2->
darkgreen'
181
182//Andjointheminanaccumulatedbar
183$accbplot=newAccBarPlot(array($bplot,$bplot2));
184$graph->
Add($accbplot);
185
186$graph->
Stroke();
187?