Guest User

Untitled

a guest
Nov 13th, 2013
178
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.44 KB | None | 0 0
  1. <?php
  2.  
  3. require_once ('jpgraph/jpgraph.php');
  4. require_once ('jpgraph/jpgraph_bar.php');
  5.  
  6. // Constants
  7. $dataFile = '/home/ftb/unleashed/onlineTime.txt';
  8.  
  9. function readplayerdata($aFile, &$playerName, &$hoursOnline) {
  10. $fileContents = @file($aFile,FILE_IGNORE_NEW_LINES|FILE_SKIP_EMPTY_LINES);
  11.  
  12. if( $fileContents === false ) {
  13. throw new JpGraphException('Can not read player activity data file.');
  14. }
  15.  
  16. for($line = 0; $line <= 29; $line++) {
  17. if(!array_key_exists($line, $fileContents)) {
  18. break;
  19. }
  20.  
  21. $split = preg_split('/[\s]+/', $fileContents[$line]);
  22. $playerName[] = trim($split[0]);
  23. $hoursOnline[] = trim($split[1]);
  24. }
  25. }
  26.  
  27. // Read data from file and store in arrays
  28. $playerName = array();
  29. $hoursOnline = array();
  30. readplayerdata($dataFile,$playerName,$hoursOnline);
  31.  
  32. // Draw bar graph
  33.  
  34. // Color scheme in hex
  35. $color1 = "#ECD078";
  36. $color1Light = "#F6E8BC";
  37. $color2 = "#D95B43";
  38. $color3 = "#C02942";
  39. $color4 = "#542437";
  40. $color5 = "#53777A";
  41.  
  42. // Setup the basic parameters for the graph
  43. $graph = new Graph(1000, 950);
  44. // Manually set scale, leaving extra room on x axis for values to fit inside plot area
  45. $graph->SetScale('textint', 0, ($hoursOnline[0] + 20), 0, 0);
  46. $graph->SetAngle(90);
  47. $graph->SetMargin(140, 40, 90, 60);
  48. $graph->SetBox(true, $color5, 1);
  49. $graph->SetMarginColor($color5);
  50. $graph->SetFrame(true, $color5, 1);
  51. $graph->SetColor($color1);
  52.  
  53. // Setup title for graph
  54. $graph->title->Set('Player activity on The Beast Unleashed');
  55. $graph->title->SetFont(FF_ARIAL,FS_BOLD,20);
  56. $graph->title->SetColor($color3);
  57. $graph->subtitle->Set("This graph shows the number of hours players have spent on the currently active map\nData is updated every 24 hours");
  58. $graph->subtitle->SetColor($color1);
  59.  
  60. // Setup X-axis.
  61. $graph->xaxis->SetTitle("User name", 'middle');
  62. $graph->xaxis->title->SetFont(FF_ARIAL,FS_NORMAL,15);
  63. $graph->xaxis->title->SetAngle(90);
  64. $graph->xaxis->title->SetColor($color3);
  65. $graph->xaxis->SetTitleMargin(110);
  66. $graph->xaxis->SetLabelMargin(5);
  67. $graph->xaxis->SetLabelAlign('right','center');
  68. $graph->xaxis->SetTickLabels($playerName);
  69. $graph->xaxis->SetFont(FF_ARIAL,FS_NORMAL,10);
  70. $graph->xaxis->SetColor($color1);
  71.  
  72. // Setup Y-axis
  73.  
  74. // First we want it at the bottom, i.e. the 'max' value of the
  75. // x-axis
  76. $graph->yaxis->SetPos('max');
  77.  
  78. // Arrange the title
  79. $graph->yaxis->SetTitle("Hours connected",'center');
  80. $graph->yaxis->SetTitleSide(SIDE_RIGHT);
  81. $graph->yaxis->title->SetFont(FF_ARIAL,FS_NORMAL,15);
  82. $graph->yaxis->title->SetAngle(0);
  83. $graph->yaxis->title->Align('center','top');
  84. $graph->yaxis->title->SetColor($color3);
  85. $graph->yaxis->SetTitleMargin(30);
  86. $graph->yaxis->SetColor($color1);
  87.  
  88. // Arrange the labels
  89. $graph->yaxis->SetLabelSide(SIDE_RIGHT);
  90. $graph->yaxis->SetLabelAlign('center','top');
  91.  
  92. // Set up the y grid
  93. $graph->ygrid->SetFill(true,$color1Light,$color1);
  94. $graph->ygrid->SetColor($color1Light, false);
  95.  
  96. // Create the bar plot
  97. $barplot = new BarPlot($hoursOnline);
  98. $graph->Add($barplot);
  99.  
  100. // Set up bar plot, must be after Add($barplot) due to bug
  101. $barplot->SetFillColor($color3);
  102. $barplot->SetColor($color3);
  103.  
  104. // Show the number of hours next to each bar
  105. $barplot->value->Show();
  106. $barplot->value->HideZero();
  107. $barplot->value->SetFont(FF_ARIAL,FS_BOLD,10);
  108. $barplot->value->SetAlign('right','center');
  109. $barplot->value->SetColor($color4);
  110. $barplot->value->SetFormat('%d');
  111.  
  112. // Render and display graph
  113. $graph->Stroke();
  114.  
  115. ?>
Advertisement
Add Comment
Please, Sign In to add comment