1<?php // content="text/plain; charset=utf-8" 2require_once '../../vendor/autoload.php'; 3use Amenadiel\JpGraph\Graph; 4use Amenadiel\JpGraph\Plot; 5 6$datay = array(2, 3, -5, 8, 12, 6, 3); 7$datax = array("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul"); 8 9// Size of graph 10$width = 400; 11$height = 500; 12 13// Set the basic parameters of the graph 14$graph = new Graph\Graph($width, $height, 'auto'); 15$graph->SetScale("textlin"); 16 17$top = 50; 18$bottom = 80; 19$left = 50; 20$right = 20; 21$graph->Set90AndMargin($left, $right, $top, $bottom); 22 23$graph->xaxis->SetPos('min'); 24 25// Nice shadow 26$graph->SetShadow(); 27 28// Setup title 29$graph->title->Set("Horizontal bar graph ex 3"); 30$graph->title->SetFont(FF_VERDANA, FS_BOLD, 14); 31$graph->subtitle->Set("(Axis at bottom)"); 32 33// Setup X-axis 34$graph->xaxis->SetTickLabels($datax); 35$graph->xaxis->SetFont(FF_FONT2, FS_BOLD, 12); 36 37// Some extra margin looks nicer 38$graph->xaxis->SetLabelMargin(5); 39 40// Label align for X-axis 41$graph->xaxis->SetLabelAlign('right', 'center'); 42 43// Add some grace to y-axis so the bars doesn't go 44// all the way to the end of the plot area 45$graph->yaxis->scale->SetGrace(20); 46 47// Setup the Y-axis to be displayed in the bottom of the 48// graph. We also finetune the exact layout of the title, 49// ticks and labels to make them look nice. 50$graph->yaxis->SetPos('max'); 51 52// First make the labels look right 53$graph->yaxis->SetLabelAlign('center', 'top'); 54$graph->yaxis->SetLabelFormat('%d'); 55$graph->yaxis->SetLabelSide(SIDE_RIGHT); 56 57// The fix the tick marks 58$graph->yaxis->SetTickSide(SIDE_LEFT); 59 60// Finally setup the title 61$graph->yaxis->SetTitleSide(SIDE_RIGHT); 62$graph->yaxis->SetTitleMargin(35); 63 64// To align the title to the right use : 65$graph->yaxis->SetTitle('Turnaround 2002', 'high'); 66$graph->yaxis->title->Align('right'); 67 68// To center the title use : 69//$graph->yaxis->SetTitle('Turnaround 2002','center'); 70//$graph->yaxis->title->Align('center'); 71 72$graph->yaxis->title->SetFont(FF_ARIAL, FS_BOLD, 12); 73$graph->yaxis->title->SetAngle(0); 74 75$graph->yaxis->SetFont(FF_FONT2, FS_NORMAL); 76// If you want the labels at an angle other than 0 or 90 77// you need to use TTF fonts 78//$graph->yaxis->SetLabelAngle(0); 79 80// Now create a bar pot 81$bplot = new Plot\BarPlot($datay); 82$bplot->SetFillColor("orange"); 83$bplot->SetShadow(); 84 85//You can change the width of the bars if you like 86//$bplot->SetWidth(0.5); 87 88// We want to display the value of each bar at the top 89$bplot->value->Show(); 90$bplot->value->SetFont(FF_ARIAL, FS_BOLD, 12); 91$bplot->value->SetAlign('left', 'center'); 92$bplot->value->SetColor("black", "darkred"); 93$bplot->value->SetFormat('%.1f mkr'); 94 95// Add the bar to the graph 96$graph->Add($bplot); 97 98$graph->Stroke(); 99