";$result=mysql_query("select * from votechildren where parentid=".$pid.";");$i=1;$countstr="";$optarr=array();while($row=mysql_fetch_array($result)){ echo "
SetScale("textlin");//下面两行是为了设置样式的,false与true有不同的样式$graph->SetBox(false);$graph->ygrid->SetFill(false);//y轴的4个值,分别为子选项最大得票数的0,1/3,2/3,1$graph->yaxis->SetTickPositions(array(0,$optmaxcount/3,$optmaxcount*2/3,$optmaxcount));//下三行意思是x轴的柱子长度是$optarr的数组的第0项,第1项……$b1plot = new BarPlot($optarr);$gbplot = new GroupBarPlot(array($b1plot));$graph->Add($gbplot);//柱子的边线为白色$b1plot->SetColor("white");//柱子颜色分别为#aa0000,#00aa00……如果还有$b1plot->SetFillColor(array('#aa0000','#00aa00','#0000aa','#aaaa00','#aa00aa','#00aaaa','#000000','#cc0000','#00cc00','#0000cc'));//标题为中文需要如下写$graph->title->SetFont(FF_SIMSUN,FS_BOLD);$graph->title->Set(iconv("UTF-8","gb2312","得票情况"));//指定动作$graph->xaxis->SetTickLabels($xaxisarr);$graph->Stroke();?>
4、jppie.php
这是用来画饼状图的,总体来说比画柱状图的jpgraph.php简单一点,
部分的代码原理与jpgraph.php是一样的
title->SetFont(FF_SIMSUN,FS_BOLD);$graph->title->Set(iconv("UTF-8","gb2312","得票比率"));//不用自己计算比率,直接塞进去,就会自动计算$p1 = new PiePlot($optarr);$graph->Add($p1);$p1->SetSliceColors(array('#aa0000','#00aa00','#0000aa','#aaaa00','#aa00aa','#00aaaa','#000000','#cc0000','#00cc00','#0000cc'));//把饼状图放到350x250画布中的横向50%,纵向60%的位置$p1->SetCenter(0.5,0.6);$graph->Stroke();?>