source: trunk/xgraph/jpgraph/Examples/odoex06.php

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