首页 > 后端开发 > php教程 > php报表类库jpgraph柱状图生成实例

php报表类库jpgraph柱状图生成实例

WBOY
发布: 2016-07-25 08:55:31
原创
961 人浏览过
  1. /**
  2. * JpGraph类生成柱状图
  3. * by bbs.it-home.org
  4. */
  5. $datay=array(); //纵坐标数据
  6. $datax=array(); //横坐标数据
  7. foreach ($usernums as $key => $value){
  8. $datay[] = $value;
  9. $datax[] = $userids[$key];
  10. }
  11. require_once (‘jpgraph-3.0.7/jpgraph/jpgraph.php');
  12. require_once (‘jpgraph-3.0.7/jpgraph/jpgraph_bar.php');
  13. // Create the graph. These two calls are always required
  14. $graph = new Graph(800,600); //图像高宽
  15. $graph->SetScale(“textlin”);
  16. $graph->xaxis->SetTickLabels($datax);
  17. $graph->xaxis->SetFont(FF_VERDANA,FS_NORMAL,10);
  18. $graph->xaxis->SetLabelAngle(30);
  19. $graph->yaxis->scale->SetGrace(20);
  20. $graph->xaxis->scale->SetGrace(20);
  21. // Add a drop shadow
  22. $graph->SetShadow();
  23. // Adjust the margin a bit to make more room for titles
  24. $graph->img->SetMargin(40,30,20,40);
  25. // Create a bar pot
  26. $bplot = new BarPlot($datay);
  27. // Adjust fill color
  28. $bplot->SetFillColor(‘orange');
  29. $bplot->value->Show();
  30. $bplot->value->SetFont(FF_ARIAL,FS_BOLD,10);
  31. $bplot->value->SetAngle(45);
  32. $bplot->value->SetFormat(‘%d');
  33. $graph->Add($bplot);
  34. // Setup the titles
  35. $graph->title->Set(iconv(“UTF-8″, “gb2312″,”用户消费报表图”));
  36. $graph->xaxis->title->Set(iconv(“UTF-8″, “gb2312″,”用户姓名”));
  37. $graph->yaxis->title->Set(iconv(“UTF-8″, “gb2312″,”用户订单数量”));
  38. $graph->xaxis->title->SetFont(FF_SIMSUN,FS_BOLD);
  39. $graph->yaxis->title->SetFont(FF_SIMSUN,FS_BOLD);
  40. $graph->title->SetFont(FF_SIMSUN,FS_BOLD);
  41. // Display the graph
  42. $graph->Stroke();
  43. ?>
复制代码

效果如下图: JpGraph生成柱状图



来源:php.cn
本站声明
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板