Home >Backend Development >PHP Tutorial >PHP report class library jpgraph histogram generation example

PHP report class library jpgraph histogram generation example

WBOY
WBOYOriginal
2016-07-25 08:55:31959browse
  1. /**
  2. * JpGraph class generates histogram
  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. ?>
复制代码

效果如下图: PHP report class library jpgraph histogram generation example



Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn