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