PHP绘图技术
前提:要启用php.ini中的extension=php_gd2.dll设置后重新启动APach2
以投票为例:
创建表
CREATE tableelector(
electorid int,
name VARCHAR(64),
voteNums int,
voteHonth int
)
INSERT INTO electorVALUES(1,'jhchen',10,2);
INSERT INTO electorVALUES(1,'jhchen',8,50);
INSERT INTO electorVALUES(1,'jhchen',9,50);
INSERT INTO electorVALUES(1,'jhchen',7,70);
INSERT INTO electorVALUES(2,'hongjiantu',7,40);
INSERT INTO electorVALUES(2,'hongjiantu',9,10);
INSERT INTO electorVALUES(2,'hongjiantu',10,70);
///
创建显示投票结果界面_showall.php
<!DOCTYPE htmlPUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<htmlxmlns="http://www.w3.org/1999/xhtml">
<head>
<title>投票结果显示中心</title>
</head>
<body>
<h1>显示网民支持情况</h1>
<imgsrc="ShowVote.php?id=1"/>
<imgsrc="ShowVote.php?id=2"/>
</body>
</html>
/
创建投票实时数据中心处理_ShowVote.php(应用jpgraph-3.0.7中的accbarframeex01.php)
<?php//content="text/plain; charset=utf-8"
require_once('jpgraph/jpgraph.php');
require_once('jpgraph/jpgraph_bar.php');
$id=$_REQUEST['id'];
$sql="select *from elector where electorId=$id order by voteHonth";
$conn=mysql_connect("localhost","root","myoa888")or die("数据库连接失败!".mysql_errno());
mysql_select_db("test",$conn)or die(mysql_error());
mysql_query("setnames 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);
//$datay1=array(13,8,19,7,17,6);
//$datay2=array(0,0,0,0,0,0);
// Create the graph.
$graph = newGraph(350,250);
$graph->SetScale('textlin');
$graph->SetMarginColor('silver');
// Setup title
$graph->title->Set($title);
$graph->title->SetFont(FF_SIMSUN,FS_BOLD,14);
// Create the firstbar
$bplot = newBarPlot($datay1);
$bplot->SetFillGradient('AntiqueWhite2','AntiqueWhite4:0.8',GRAD_VERT);
$bplot->SetColor('darkred');
// Create the secondbar
$bplot2 = newBarPlot($datay2);
$bplot2->SetFillGradient('olivedrab1','olivedrab4',GRAD_VERT);
$bplot2->SetColor('darkgreen');
// And join them inan accumulated bar
$accbplot = newAccBarPlot(array($bplot,$bplot2));
$graph->Add($accbplot);
$graph->Stroke();
?>