php报表 jpgraph柱状图实例

jpgraph是php中一个非常非常强大的第三方报表工具,据说能完成一切你想要的图形…新手初识jpgraph肯定会遇到各种各样的问题,比如乱码什么的,本案例是jpgraph3.0.7制作,也经过本人的多次实验,解决乱码问题.

php报表 jpgraph柱状图实例代码如下:

  1. <?php$
  2. datay=array(); //纵坐标数据
  3. $datax=array(); //横坐标数据
  4. foreach ($usernums as $key => $value){
  5. $datay[] = $value;
  6. $datax[] = $userids[$key];
  7. }
  8. require_once (‘jpgraph-3.0.7/jpgraph/jpgraph.php’);
  9. require_once (‘jpgraph-3.0.7/jpgraph/jpgraph_bar.php’);
  10. // Create the graph. These two calls are always required
  11. $graph = new Graph(800,600); //图像高宽
  12. $graph->SetScale(“textlin”);
  13. $graph->xaxis->SetTickLabels($datax);
  14. $graph->xaxis->SetFont(FF_VERDANA,FS_NORMAL,10);
  15. $graph->xaxis->SetLabelAngle(30);
  16. $graph->yaxis->scale->SetGrace(20);
  17. $graph->xaxis->scale->SetGrace(20);// Add a drop shadow
  18. $graph->SetShadow();// Adjust the margin a bit to make more room for titles
  19. $graph->img->SetMargin(40,30,20,40);// Create a bar pot
  20. $bplot = new BarPlot($datay);// Adjust fill color
  21. $bplot->SetFillColor(‘orange’);
  22. $bplot->value->Show();$bplot->value->SetFont(FF_ARIAL,FS_BOLD,10);//开源代码phpfensi.com
  23. $bplot->value->SetAngle(45);
  24. $bplot->value->SetFormat(‘%d’);
  25. $graph->Add($bplot);// Setup the titles
  26. $graph->title->Set(iconv(“UTF-8″, “gb2312″,”用户消费报表图”));
  27. $graph->xaxis->title->Set(iconv(“UTF-8″, “gb2312″,”用户姓名”));
  28. $graph->yaxis->title->Set(iconv(“UTF-8″, “gb2312″,”用户订单数量”));
  29. $graph->xaxis->title->SetFont(FF_SIMSUN,FS_BOLD);
  30. $graph->yaxis->title->SetFont(FF_SIMSUN,FS_BOLD);
  31. $graph->title->SetFont(FF_SIMSUN,FS_BOLD);// Display the graph
  32. $graph->Stroke();
  33. ?>