jpgraph是php中一个非常非常强大的第三方报表工具,据说能完成一切你想要的图形…新手初识jpgraph肯定会遇到各种各样的问题,比如乱码什么的,本案例是jpgraph3.0.7制作,也经过本人的多次实验,解决乱码问题.
php报表 jpgraph柱状图实例代码如下:
- <?php$
- datay=array();
- $datax=array();
- foreach ($usernums as $key => $value){
- $datay[] = $value;
- $datax[] = $userids[$key];
- }
- require_once (‘jpgraph-3.0.7/jpgraph/jpgraph.php’);
- require_once (‘jpgraph-3.0.7/jpgraph/jpgraph_bar.php’);
-
- $graph = new Graph(800,600);
- $graph->SetScale(“textlin”);
- $graph->xaxis->SetTickLabels($datax);
- $graph->xaxis->SetFont(FF_VERDANA,FS_NORMAL,10);
- $graph->xaxis->SetLabelAngle(30);
- $graph->yaxis->scale->SetGrace(20);
- $graph->xaxis->scale->SetGrace(20);
- $graph->SetShadow();
- $graph->img->SetMargin(40,30,20,40);
- $bplot = new BarPlot($datay);
- $bplot->SetFillColor(‘orange’);
- $bplot->value->Show();$bplot->value->SetFont(FF_ARIAL,FS_BOLD,10);
- $bplot->value->SetAngle(45);
- $bplot->value->SetFormat(‘%d’);
- $graph->Add($bplot);
- $graph->title->Set(iconv(“UTF-8″, “gb2312″,”用户消费报表图”));
- $graph->xaxis->title->Set(iconv(“UTF-8″, “gb2312″,”用户姓名”));
- $graph->yaxis->title->Set(iconv(“UTF-8″, “gb2312″,”用户订单数量”));
- $graph->xaxis->title->SetFont(FF_SIMSUN,FS_BOLD);
- $graph->yaxis->title->SetFont(FF_SIMSUN,FS_BOLD);
- $graph->title->SetFont(FF_SIMSUN,FS_BOLD);
- $graph->Stroke();
- ?>
|