1 | <?php // content="text/plain; charset=utf-8" |
---|
2 | require_once ('jpgraph/jpgraph.php'); |
---|
3 | require_once ('jpgraph/jpgraph_bar.php'); |
---|
4 | |
---|
5 | // Callback function for Y-scale to get 1000 separator on labels |
---|
6 | function separator1000($aVal) { |
---|
7 | return number_format($aVal); |
---|
8 | } |
---|
9 | |
---|
10 | function separator1000_usd($aVal) { |
---|
11 | return '$'.number_format($aVal); |
---|
12 | } |
---|
13 | |
---|
14 | // Some data |
---|
15 | $datay=array(120567,134013,192000,87000); |
---|
16 | |
---|
17 | // Create the graph and setup the basic parameters |
---|
18 | $graph = new Graph(500,300,'auto'); |
---|
19 | $graph->img->SetMargin(80,30,30,40); |
---|
20 | $graph->SetScale('textint'); |
---|
21 | $graph->SetShadow(); |
---|
22 | $graph->SetFrame(false); // No border around the graph |
---|
23 | |
---|
24 | // Add some grace to the top so that the scale doesn't |
---|
25 | // end exactly at the max value. |
---|
26 | // The grace value is the percetage of additional scale |
---|
27 | // value we add. Specifying 50 means that we add 50% of the |
---|
28 | // max value |
---|
29 | $graph->yaxis->scale->SetGrace(50); |
---|
30 | $graph->yaxis->SetLabelFormatCallback('separator1000'); |
---|
31 | |
---|
32 | // Setup X-axis labels |
---|
33 | $a = $gDateLocale->GetShortMonth(); |
---|
34 | $graph->xaxis->SetTickLabels($a); |
---|
35 | $graph->xaxis->SetFont(FF_FONT2); |
---|
36 | |
---|
37 | // Setup graph title ands fonts |
---|
38 | $graph->title->Set('Example of Y-scale callback formatting'); |
---|
39 | $graph->title->SetFont(FF_FONT2,FS_BOLD); |
---|
40 | $graph->xaxis->title->Set('Year 2002'); |
---|
41 | $graph->xaxis->title->SetFont(FF_FONT2,FS_BOLD); |
---|
42 | |
---|
43 | // Create a bar pot |
---|
44 | $bplot = new BarPlot($datay); |
---|
45 | $bplot->SetFillColor('orange'); |
---|
46 | $bplot->SetWidth(0.5); |
---|
47 | $bplot->SetShadow(); |
---|
48 | |
---|
49 | // Setup the values that are displayed on top of each bar |
---|
50 | $bplot->value->Show(); |
---|
51 | |
---|
52 | // Must use TTF fonts if we want text at an arbitrary angle |
---|
53 | $bplot->value->SetFont(FF_ARIAL,FS_BOLD); |
---|
54 | $bplot->value->SetAngle(45); |
---|
55 | $bplot->value->SetFormatCallback('separator1000_usd'); |
---|
56 | |
---|
57 | // Black color for positive values and darkred for negative values |
---|
58 | $bplot->value->SetColor('black','darkred'); |
---|
59 | $graph->Add($bplot); |
---|
60 | |
---|
61 | // Finally stroke the graph |
---|
62 | $graph->Stroke(); |
---|
63 | ?> |
---|