1 | <?php
|
---|
2 | //=============================================================================
|
---|
3 | // File: ODOEX08.PHP
|
---|
4 | // Description: Example 1 for odometer graphs
|
---|
5 | // Created: 2002-02-22
|
---|
6 | // Version: $Id$
|
---|
7 | //
|
---|
8 | // Comment:
|
---|
9 | // Example file for odometer graph. This examples extends odoex07
|
---|
10 | // by showing how 1) a drop shadow may be added to the frame
|
---|
11 | // 2) Change the margin color 3) Change the fill color of the odometer
|
---|
12 | // 4) adding a drop shadow to the indicator needles
|
---|
13 | //
|
---|
14 | // Copyright (C) 2002 Johan Persson. All rights reserved.
|
---|
15 | //=============================================================================
|
---|
16 | require_once ('jpgraph/jpgraph.php');
|
---|
17 | require_once ('jpgraph/jpgraph_odo.php');
|
---|
18 |
|
---|
19 | //---------------------------------------------------------------------
|
---|
20 | // Create a new odometer graph (width=250, height=200 pixels)
|
---|
21 | //---------------------------------------------------------------------
|
---|
22 | $graph = new OdoGraph(250,250);
|
---|
23 |
|
---|
24 | //---------------------------------------------------------------------
|
---|
25 | // Add a drop shadow to the fram
|
---|
26 | //---------------------------------------------------------------------
|
---|
27 | $graph->SetShadow();
|
---|
28 |
|
---|
29 | //---------------------------------------------------------------------
|
---|
30 | // Change the color of the odometer plotcanvas. NOT the odometer
|
---|
31 | // fill color itself.
|
---|
32 | //---------------------------------------------------------------------
|
---|
33 | $graph->SetColor("lightyellow");
|
---|
34 |
|
---|
35 | //---------------------------------------------------------------------
|
---|
36 | // Change the color of the margin in the graph
|
---|
37 | //---------------------------------------------------------------------
|
---|
38 | $graph->SetMarginColor("khaki:0.6");
|
---|
39 |
|
---|
40 | //---------------------------------------------------------------------
|
---|
41 | // Specify title and subtitle using default fonts
|
---|
42 | // * Note each title may be multilines by using a '\n' as a line
|
---|
43 | // divider.
|
---|
44 | //---------------------------------------------------------------------
|
---|
45 | $graph->title->Set("Odometer title");
|
---|
46 | $graph->title->SetColor("white");
|
---|
47 | $graph->subtitle->Set("2002-02-13");
|
---|
48 | $graph->subtitle->SetColor("white");
|
---|
49 |
|
---|
50 | //---------------------------------------------------------------------
|
---|
51 | // Specify caption.
|
---|
52 | // * (This is the text at the bottom of the graph.) The margins will
|
---|
53 | // automatically adjust to fit the height of the text. A caption
|
---|
54 | // may have multiple lines by including a '\n' character in the
|
---|
55 | // string.
|
---|
56 | //---------------------------------------------------------------------
|
---|
57 | $graph->caption->Set("First caption row\n... second row");
|
---|
58 | $graph->caption->SetColor("white");
|
---|
59 |
|
---|
60 | //---------------------------------------------------------------------
|
---|
61 | // Now we need to create an odometer to add to the graph.
|
---|
62 | // By default the scale will be 0 to 100
|
---|
63 | //---------------------------------------------------------------------
|
---|
64 | $odo = new Odometer(ODO_FULL);
|
---|
65 |
|
---|
66 | //---------------------------------------------------------------------
|
---|
67 | // Set fill color for odometer
|
---|
68 | //---------------------------------------------------------------------
|
---|
69 | $odo->SetColor("lightblue");
|
---|
70 |
|
---|
71 | //---------------------------------------------------------------------
|
---|
72 | // Set color indication
|
---|
73 | //---------------------------------------------------------------------
|
---|
74 | $odo->AddIndication(0,50,"green");
|
---|
75 | $odo->AddIndication(50,80,"yellow");
|
---|
76 | $odo->AddIndication(80,100,"red");
|
---|
77 |
|
---|
78 | //---------------------------------------------------------------------
|
---|
79 | // Set the center area that will not be affected by the color bands
|
---|
80 | //---------------------------------------------------------------------
|
---|
81 | $odo->SetCenterAreaWidth(0.4); // Fraction of radius
|
---|
82 |
|
---|
83 | //---------------------------------------------------------------------
|
---|
84 | // Adjust scale ticks to be shown at 10 steps interval and scale
|
---|
85 | // labels at every second tick
|
---|
86 | //---------------------------------------------------------------------
|
---|
87 | $odo->scale->SetTicks(10,2);
|
---|
88 |
|
---|
89 | //---------------------------------------------------------------------
|
---|
90 | // Make the tick marks 2 pixel wide
|
---|
91 | //---------------------------------------------------------------------
|
---|
92 | $odo->scale->SetTickWeight(2);
|
---|
93 |
|
---|
94 | //---------------------------------------------------------------------
|
---|
95 | // Use a bold font for tick labels
|
---|
96 | //---------------------------------------------------------------------
|
---|
97 | $odo->scale->label->SetFont(FF_FONT1, FS_BOLD);
|
---|
98 |
|
---|
99 | //---------------------------------------------------------------------
|
---|
100 | // Change the start and end angle for the scale
|
---|
101 | //---------------------------------------------------------------------
|
---|
102 | $odo->scale->SetAngle(20,340);
|
---|
103 |
|
---|
104 | //---------------------------------------------------------------------
|
---|
105 | // Set display value for the odometer
|
---|
106 | //---------------------------------------------------------------------
|
---|
107 | $odo->needle->Set(64);
|
---|
108 |
|
---|
109 | //---------------------------------------------------------------------
|
---|
110 | // Specify scale caption. Note that depending on the position of the
|
---|
111 | // indicator needle this label might be partially hidden.
|
---|
112 | //---------------------------------------------------------------------
|
---|
113 | $odo->label->Set("% Passed");
|
---|
114 |
|
---|
115 | //---------------------------------------------------------------------
|
---|
116 | // Set a new style for the needle
|
---|
117 | //---------------------------------------------------------------------
|
---|
118 | $odo->needle->SetStyle(NEEDLE_STYLE_MEDIUM_TRIANGLE);
|
---|
119 | $odo->needle->SetLength(0.7); // Length as 70% of the radius
|
---|
120 | $odo->needle->SetFillColor("orange");
|
---|
121 |
|
---|
122 | //---------------------------------------------------------------------
|
---|
123 | // Setup the second indicator needle
|
---|
124 | //---------------------------------------------------------------------
|
---|
125 | $odo->needle2->Set(15);
|
---|
126 | $odo->needle2->SetStyle(NEEDLE_STYLE_SMALL_TRIANGLE);
|
---|
127 | $odo->needle2->SetLength(0.55); // Length as 70% of the radius
|
---|
128 | $odo->needle2->SetFillColor("lightgray");
|
---|
129 |
|
---|
130 | // Only the first needle is shown by default
|
---|
131 | $odo->needle2->Show();
|
---|
132 |
|
---|
133 | //---------------------------------------------------------------------
|
---|
134 | // Add a drop shadow to the indicator needles
|
---|
135 | //---------------------------------------------------------------------
|
---|
136 | $odo->needle->SetShadow();
|
---|
137 | $odo->needle2->SetShadow();
|
---|
138 |
|
---|
139 | //---------------------------------------------------------------------
|
---|
140 | // Add the odometer to the graph
|
---|
141 | //---------------------------------------------------------------------
|
---|
142 | $graph->Add($odo);
|
---|
143 |
|
---|
144 | //---------------------------------------------------------------------
|
---|
145 | // ... and finally stroke and stream the image back to the browser
|
---|
146 | //---------------------------------------------------------------------
|
---|
147 | $graph->Stroke();
|
---|
148 |
|
---|
149 | // EOF
|
---|
150 | ?> |
---|