<?php //复制到htdocs并配一下,把所有文件剪切出来 //显示中文的方法 //经验,不能有任何的echo输出,头中也不能使用空格,有的相不想让女朋友之方法 //引用此jpgraph的图片也很简单使用img即可 //如何传参数呢?还是使用$_GET; ?> <html> <head> <title>使用jpgraph显示SB图表</title> </head> <body> <img src="showVote.php?wc=yourmother" width="500px"> <img src="showVote.php?wc=yourfather" width="500px"> </body> </html>
一个从论坛上找的例子,只是为了说明如何在X轴上加名子的。
<?php include ("jpgraph/jpgraph.php"); include ("jpgraph/jpgraph_bar.php"); $file = fopen("datay.txt", r); $i = 0; while ($line = fgets($file,4096)) { list($x,$y) = explode(" ", $line); $datay[$i] = $y; $i++; } fclose($file); //var_dump($datay); //$datay=array(160,180,203,289,405,488,489,408,299,166,187,105); //创建画布 $graph = new Graph(600,300,"auto"); $graph->SetScale("textlin"); $graph->yaxis->scale->SetGrace(20); $graph->yaxis->scale->SetAutoMin(10); $graph->yscale->SetGrace(10,10); //创建画布阴影 $graph->SetShadow(); //设置显示区左、右、上、下距边线的距离,单位为像素 $graph->img->SetMargin(40,30,30,40); //创建一个矩形的对象 $bplot = new BarPlot($datay); //设置柱形图的颜色 $bplot->SetFillColor('orange'); //设置显示数字 $bplot->value->Show(); //在柱形图中显示格式化的图书销量 $bplot->value->SetFormat('%d'); //将柱形图添加到图像中 $graph->Add($bplot); //设置画布背景色为淡蓝色 $graph->SetMarginColor("lightblue"); //创建标题 $graph->title->Set("hello"); //设置X坐标轴文字 //$a=array("1月","2月","3月","4月","5月","6月","7月","8月","9月","10月","11月","12月"); $a=array("1月","2月","3月"); $graph->xaxis->SetTickLabels($a); //设置字体 $graph->title->SetFont(FF_SIMSUN); $graph->xaxis->SetFont(FF_SIMSUN); //输出矩形图表 $graph->Stroke(); ?>