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