PHP投票系统报表(jpgraph-3.0.7)

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();

?>

 

 

 

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值