[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(3,7,19,11,4,20);
|
---|
| 7 |
|
---|
| 8 | // Create the graph and setup the basic parameters
|
---|
| 9 | $graph = new Graph(350,200,'auto');
|
---|
| 10 | $graph->img->SetMargin(40,30,40,40);
|
---|
| 11 | $graph->SetScale("textint");
|
---|
| 12 | $graph->SetFrame(true,'blue',1);
|
---|
| 13 | $graph->SetColor('lightblue');
|
---|
| 14 | $graph->SetMarginColor('lightblue');
|
---|
| 15 |
|
---|
| 16 | // Add some grace to the top so that the scale doesn't
|
---|
| 17 | // end exactly at the max value.
|
---|
| 18 | //$graph->yaxis->scale->SetGrace(20);
|
---|
| 19 |
|
---|
| 20 | // Setup X-axis labels
|
---|
| 21 | $a = $gDateLocale->GetShortMonth();
|
---|
| 22 | $graph->xaxis->SetTickLabels($a);
|
---|
| 23 | $graph->xaxis->SetFont(FF_FONT1);
|
---|
| 24 | $graph->xaxis->SetColor('darkblue','black');
|
---|
| 25 |
|
---|
| 26 | // Stup "hidden" y-axis by given it the same color
|
---|
| 27 | // as the background
|
---|
| 28 | $graph->yaxis->SetColor('lightblue','darkblue');
|
---|
| 29 | $graph->ygrid->SetColor('white');
|
---|
| 30 |
|
---|
| 31 | // Setup graph title ands fonts
|
---|
| 32 | $graph->title->Set('Example of integer Y-scale');
|
---|
| 33 | $graph->subtitle->Set('(With "hidden" y-axis)');
|
---|
| 34 |
|
---|
| 35 | $graph->title->SetFont(FF_FONT2,FS_BOLD);
|
---|
| 36 | $graph->xaxis->title->Set("Year 2002");
|
---|
| 37 | $graph->xaxis->title->SetFont(FF_FONT2,FS_BOLD);
|
---|
| 38 |
|
---|
| 39 | // Create a bar pot
|
---|
| 40 | $bplot = new BarPlot($datay);
|
---|
| 41 | $bplot->SetFillColor('darkblue');
|
---|
| 42 | $bplot->SetColor('darkblue');
|
---|
| 43 | $bplot->SetWidth(0.5);
|
---|
| 44 | $bplot->SetShadow('darkgray');
|
---|
| 45 |
|
---|
| 46 | // Setup the values that are displayed on top of each bar
|
---|
| 47 | $bplot->value->Show();
|
---|
| 48 | // Must use TTF fonts if we want text at an arbitrary angle
|
---|
| 49 | $bplot->value->SetFont(FF_ARIAL,FS_NORMAL,8);
|
---|
| 50 | $bplot->value->SetFormat('$%d');
|
---|
| 51 | // Black color for positive values and darkred for negative values
|
---|
| 52 | $bplot->value->SetColor("black","darkred");
|
---|
| 53 | $graph->Add($bplot);
|
---|
| 54 |
|
---|
| 55 | // Finally stroke the graph
|
---|
| 56 | $graph->Stroke();
|
---|
| 57 | ?>
|
---|