Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- require_once ('jpgraph/jpgraph.php');
- require_once ('jpgraph/jpgraph_bar.php');
- // Constants
- $dataFile = '/home/ftb/unleashed/onlineTime.txt';
- function readplayerdata($aFile, &$playerName, &$hoursOnline) {
- $fileContents = @file($aFile,FILE_IGNORE_NEW_LINES|FILE_SKIP_EMPTY_LINES);
- if( $fileContents === false ) {
- throw new JpGraphException('Can not read player activity data file.');
- }
- for($line = 0; $line <= 29; $line++) {
- if(!array_key_exists($line, $fileContents)) {
- break;
- }
- $split = preg_split('/[\s]+/', $fileContents[$line]);
- $playerName[] = trim($split[0]);
- $hoursOnline[] = trim($split[1]);
- }
- }
- // Read data from file and store in arrays
- $playerName = array();
- $hoursOnline = array();
- readplayerdata($dataFile,$playerName,$hoursOnline);
- // Draw bar graph
- // Color scheme in hex
- $color1 = "#ECD078";
- $color1Light = "#F6E8BC";
- $color2 = "#D95B43";
- $color3 = "#C02942";
- $color4 = "#542437";
- $color5 = "#53777A";
- // Setup the basic parameters for the graph
- $graph = new Graph(1000, 950);
- // Manually set scale, leaving extra room on x axis for values to fit inside plot area
- $graph->SetScale('textint', 0, ($hoursOnline[0] + 20), 0, 0);
- $graph->SetAngle(90);
- $graph->SetMargin(140, 40, 90, 60);
- $graph->SetBox(true, $color5, 1);
- $graph->SetMarginColor($color5);
- $graph->SetFrame(true, $color5, 1);
- $graph->SetColor($color1);
- // Setup title for graph
- $graph->title->Set('Player activity on The Beast Unleashed');
- $graph->title->SetFont(FF_ARIAL,FS_BOLD,20);
- $graph->title->SetColor($color3);
- $graph->subtitle->Set("This graph shows the number of hours players have spent on the currently active map\nData is updated every 24 hours");
- $graph->subtitle->SetColor($color1);
- // Setup X-axis.
- $graph->xaxis->SetTitle("User name", 'middle');
- $graph->xaxis->title->SetFont(FF_ARIAL,FS_NORMAL,15);
- $graph->xaxis->title->SetAngle(90);
- $graph->xaxis->title->SetColor($color3);
- $graph->xaxis->SetTitleMargin(110);
- $graph->xaxis->SetLabelMargin(5);
- $graph->xaxis->SetLabelAlign('right','center');
- $graph->xaxis->SetTickLabels($playerName);
- $graph->xaxis->SetFont(FF_ARIAL,FS_NORMAL,10);
- $graph->xaxis->SetColor($color1);
- // Setup Y-axis
- // First we want it at the bottom, i.e. the 'max' value of the
- // x-axis
- $graph->yaxis->SetPos('max');
- // Arrange the title
- $graph->yaxis->SetTitle("Hours connected",'center');
- $graph->yaxis->SetTitleSide(SIDE_RIGHT);
- $graph->yaxis->title->SetFont(FF_ARIAL,FS_NORMAL,15);
- $graph->yaxis->title->SetAngle(0);
- $graph->yaxis->title->Align('center','top');
- $graph->yaxis->title->SetColor($color3);
- $graph->yaxis->SetTitleMargin(30);
- $graph->yaxis->SetColor($color1);
- // Arrange the labels
- $graph->yaxis->SetLabelSide(SIDE_RIGHT);
- $graph->yaxis->SetLabelAlign('center','top');
- // Set up the y grid
- $graph->ygrid->SetFill(true,$color1Light,$color1);
- $graph->ygrid->SetColor($color1Light, false);
- // Create the bar plot
- $barplot = new BarPlot($hoursOnline);
- $graph->Add($barplot);
- // Set up bar plot, must be after Add($barplot) due to bug
- $barplot->SetFillColor($color3);
- $barplot->SetColor($color3);
- // Show the number of hours next to each bar
- $barplot->value->Show();
- $barplot->value->HideZero();
- $barplot->value->SetFont(FF_ARIAL,FS_BOLD,10);
- $barplot->value->SetAlign('right','center');
- $barplot->value->SetColor($color4);
- $barplot->value->SetFormat('%d');
- // Render and display graph
- $graph->Stroke();
- ?>
Advertisement
Add Comment
Please, Sign In to add comment