[42] | 1 | <?php // content="text/plain; charset=utf-8" |
---|
| 2 | require_once ('jpgraph/jpgraph.php'); |
---|
| 3 | require_once ('jpgraph/jpgraph_bar.php'); |
---|
| 4 | |
---|
| 5 | // Some data |
---|
| 6 | $datay=array(7,19,11,4,20); |
---|
| 7 | |
---|
| 8 | // Create the graph and setup the basic parameters |
---|
| 9 | $graph = new Graph(300,200,'auto'); |
---|
| 10 | $graph->img->SetMargin(40,30,40,50); |
---|
| 11 | $graph->SetScale("textint"); |
---|
| 12 | $graph->SetFrame(true,'blue',1); |
---|
| 13 | $graph->SetColor('lightblue'); |
---|
| 14 | $graph->SetMarginColor('lightblue'); |
---|
| 15 | |
---|
| 16 | // Setup X-axis labels |
---|
| 17 | $a = $gDateLocale->GetShortMonth(); |
---|
| 18 | $graph->xaxis->SetTickLabels($a); |
---|
| 19 | $graph->xaxis->SetFont(FF_FONT1); |
---|
| 20 | $graph->xaxis->SetColor('darkblue','black'); |
---|
| 21 | |
---|
| 22 | // Setup "hidden" y-axis by given it the same color |
---|
| 23 | // as the background (this could also be done by setting the weight |
---|
| 24 | // to zero) |
---|
| 25 | $graph->yaxis->SetColor('lightblue','darkblue'); |
---|
| 26 | $graph->ygrid->SetColor('white'); |
---|
| 27 | |
---|
| 28 | // Setup graph title ands fonts |
---|
| 29 | $graph->title->Set('Using grace = 0'); |
---|
| 30 | $graph->title->SetFont(FF_FONT2,FS_BOLD); |
---|
| 31 | $graph->xaxis->SetTitle('Year 2002','center'); |
---|
| 32 | $graph->xaxis->SetTitleMargin(10); |
---|
| 33 | $graph->xaxis->title->SetFont(FF_FONT2,FS_BOLD); |
---|
| 34 | |
---|
| 35 | // Add some grace to the top so that the scale doesn't |
---|
| 36 | // end exactly at the max value. |
---|
| 37 | $graph->yaxis->scale->SetGrace(0); |
---|
| 38 | |
---|
| 39 | |
---|
| 40 | // Create a bar pot |
---|
| 41 | $bplot = new BarPlot($datay); |
---|
| 42 | $bplot->SetFillColor('darkblue'); |
---|
| 43 | $bplot->SetColor('darkblue'); |
---|
| 44 | $bplot->SetWidth(0.5); |
---|
| 45 | $bplot->SetShadow('darkgray'); |
---|
| 46 | |
---|
| 47 | // Setup the values that are displayed on top of each bar |
---|
| 48 | // Must use TTF fonts if we want text at an arbitrary angle |
---|
| 49 | $bplot->value->Show(); |
---|
| 50 | $bplot->value->SetFont(FF_ARIAL,FS_NORMAL,8); |
---|
| 51 | $bplot->value->SetFormat('$%d'); |
---|
| 52 | $bplot->value->SetColor('darkred'); |
---|
| 53 | $bplot->value->SetAngle(45); |
---|
| 54 | $graph->Add($bplot); |
---|
| 55 | |
---|
| 56 | // Finally stroke the graph |
---|
| 57 | $graph->Stroke(); |
---|
| 58 | ?> |
---|