1 | <?php // content="text/plain; charset=utf-8" |
---|
2 | require_once ('jpgraph/jpgraph.php'); |
---|
3 | require_once ('jpgraph/jpgraph_line.php'); |
---|
4 | |
---|
5 | // A function to return the Roman Numeral, given an integer |
---|
6 | function numberToRoman($aNum) |
---|
7 | { |
---|
8 | // Make sure that we only use the integer portion of the value |
---|
9 | $n = intval($aNum); |
---|
10 | $result = ''; |
---|
11 | |
---|
12 | // Declare a lookup array that we will use to traverse the number: |
---|
13 | $lookup = array('M' => 1000, 'CM' => 900, 'D' => 500, 'CD' => 400, |
---|
14 | 'C' => 100, 'XC' => 90, 'L' => 50, 'XL' => 40, |
---|
15 | 'X' => 10, 'IX' => 9, 'V' => 5, 'IV' => 4, 'I' => 1); |
---|
16 | |
---|
17 | foreach ($lookup as $roman => $value) |
---|
18 | { |
---|
19 | // Determine the number of matches |
---|
20 | $matches = intval($n / $value); |
---|
21 | |
---|
22 | // Store that many characters |
---|
23 | $result .= str_repeat($roman, $matches); |
---|
24 | |
---|
25 | // Substract that from the number |
---|
26 | $n = $n % $value; |
---|
27 | } |
---|
28 | |
---|
29 | // The Roman numeral should be built, return it |
---|
30 | return $result; |
---|
31 | } |
---|
32 | |
---|
33 | function formatCallback($aVal) { |
---|
34 | return '('.numberToRoman($aVal).')'; |
---|
35 | } |
---|
36 | |
---|
37 | |
---|
38 | // Some (random) data |
---|
39 | $ydata = array(11,3,8,12,5,1,9,13,5,7); |
---|
40 | |
---|
41 | // Size of the overall graph |
---|
42 | $width=350; |
---|
43 | $height=250; |
---|
44 | |
---|
45 | // Create the graph and set a scale. |
---|
46 | // These two calls are always required |
---|
47 | $graph = new Graph($width,$height); |
---|
48 | $graph->SetScale('intlin'); |
---|
49 | $graph->SetShadow(); |
---|
50 | |
---|
51 | // Setup margin and titles |
---|
52 | $graph->SetMargin(40,20,20,40); |
---|
53 | $graph->title->Set('Calls per operator'); |
---|
54 | $graph->subtitle->Set('(March 12, 2008)'); |
---|
55 | $graph->xaxis->title->Set('Operator'); |
---|
56 | $graph->yaxis->title->Set('# of calls'); |
---|
57 | |
---|
58 | $graph->yaxis->title->SetFont( FF_FONT1 , FS_BOLD ); |
---|
59 | $graph->xaxis->title->SetFont( FF_FONT1 , FS_BOLD ); |
---|
60 | |
---|
61 | $graph->yaxis->SetColor('blue'); |
---|
62 | |
---|
63 | // Create the linear plot |
---|
64 | $lineplot=new LinePlot($ydata); |
---|
65 | $lineplot->SetColor( 'blue' ); |
---|
66 | $lineplot->SetWeight( 2 ); // Two pixel wide |
---|
67 | $lineplot->mark->SetType(MARK_UTRIANGLE); |
---|
68 | $lineplot->mark->SetColor('blue'); |
---|
69 | $lineplot->mark->SetFillColor('red'); |
---|
70 | |
---|
71 | $lineplot->value->Show(); |
---|
72 | $lineplot->value->SetFont(FF_ARIAL,FS_BOLD,10); |
---|
73 | $lineplot->value->SetColor('darkred'); |
---|
74 | $lineplot->value->SetFormatCallback('formatCallback'); |
---|
75 | |
---|
76 | // Add the plot to the graph |
---|
77 | $graph->Add($lineplot); |
---|
78 | |
---|
79 | // Display the graph |
---|
80 | $graph->Stroke(); |
---|
81 | ?> |
---|