Rumah >pembangunan bahagian belakang >tutorial php >php报表类库jpgraph柱状图生成实例

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

WBOY
WBOYasal
2016-07-25 08:55:31959semak imbas
  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生成柱状图



Kenyataan:
Kandungan artikel ini disumbangkan secara sukarela oleh netizen, dan hak cipta adalah milik pengarang asal. Laman web ini tidak memikul tanggungjawab undang-undang yang sepadan. Jika anda menemui sebarang kandungan yang disyaki plagiarisme atau pelanggaran, sila hubungi admin@php.cn