[42] | 1 | <?php
|
---|
| 2 | //=============================================================================
|
---|
| 3 | // File: ODOEX04.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 odoex03
|
---|
| 10 | // by 1) changing the indicator needle style and color 2) Introducing
|
---|
| 11 | // a half circle in the middle that is not affetced by the indicator bands.
|
---|
| 12 | //
|
---|
| 13 | // Copyright (C) 2002 Johan Persson. All rights reserved.
|
---|
| 14 | //=============================================================================
|
---|
| 15 | require_once ('jpgraph/jpgraph.php');
|
---|
| 16 | require_once ('jpgraph/jpgraph_odo.php');
|
---|
| 17 |
|
---|
| 18 | //---------------------------------------------------------------------
|
---|
| 19 | // Create a new odometer graph (width=250, height=200 pixels)
|
---|
| 20 | //---------------------------------------------------------------------
|
---|
| 21 | $graph = new OdoGraph(250,200);
|
---|
| 22 |
|
---|
| 23 | //---------------------------------------------------------------------
|
---|
| 24 | // Specify title and subtitle using default fonts
|
---|
| 25 | // * Note each title may be multilines by using a '\n' as a line
|
---|
| 26 | // divider.
|
---|
| 27 | //---------------------------------------------------------------------
|
---|
| 28 | $graph->title->Set("Odometer title");
|
---|
| 29 | $graph->title->SetColor("white");
|
---|
| 30 | $graph->subtitle->Set("2002-02-13");
|
---|
| 31 | $graph->subtitle->SetColor("white");
|
---|
| 32 |
|
---|
| 33 | //---------------------------------------------------------------------
|
---|
| 34 | // Specify caption.
|
---|
| 35 | // * (This is the text at the bottom of the graph.) The margins will
|
---|
| 36 | // automatically adjust to fit the height of the text. A caption
|
---|
| 37 | // may have multiple lines by including a '\n' character in the
|
---|
| 38 | // string.
|
---|
| 39 | //---------------------------------------------------------------------
|
---|
| 40 | $graph->caption->Set("First caption row\n... second row");
|
---|
| 41 | $graph->caption->SetColor("white");
|
---|
| 42 |
|
---|
| 43 | //---------------------------------------------------------------------
|
---|
| 44 | // Now we need to create an odometer to add to the graph.
|
---|
| 45 | // By default the scale will be 0 to 100
|
---|
| 46 | //---------------------------------------------------------------------
|
---|
| 47 | $odo = new Odometer();
|
---|
| 48 |
|
---|
| 49 | //---------------------------------------------------------------------
|
---|
| 50 | // Set color indication
|
---|
| 51 | //---------------------------------------------------------------------
|
---|
| 52 | $odo->AddIndication(0,50,"green");
|
---|
| 53 | $odo->AddIndication(50,80,"yellow");
|
---|
| 54 | $odo->AddIndication(80,100,"red");
|
---|
| 55 |
|
---|
| 56 | //---------------------------------------------------------------------
|
---|
| 57 | // Set the center area that will not be affected by the color bands
|
---|
| 58 | //---------------------------------------------------------------------
|
---|
| 59 | $odo->SetCenterAreaWidth(0.4); // Fraction of radius
|
---|
| 60 |
|
---|
| 61 | //---------------------------------------------------------------------
|
---|
| 62 | // Adjust scale ticks to be shown at 10 steps interval and scale
|
---|
| 63 | // labels at every second tick
|
---|
| 64 | //---------------------------------------------------------------------
|
---|
| 65 | $odo->scale->SetTicks(10,2);
|
---|
| 66 |
|
---|
| 67 | //---------------------------------------------------------------------
|
---|
| 68 | // Use a bold font for tick labels
|
---|
| 69 | //---------------------------------------------------------------------
|
---|
| 70 | $odo->scale->label->SetFont(FF_FONT1, FS_BOLD);
|
---|
| 71 |
|
---|
| 72 | //---------------------------------------------------------------------
|
---|
| 73 | // Set display value for the odometer
|
---|
| 74 | //---------------------------------------------------------------------
|
---|
| 75 | $odo->needle->Set(30);
|
---|
| 76 |
|
---|
| 77 | //---------------------------------------------------------------------
|
---|
| 78 | // Set a new style for the needle
|
---|
| 79 | //---------------------------------------------------------------------
|
---|
| 80 | $odo->needle->SetStyle(NEEDLE_STYLE_MEDIUM_TRIANGLE);
|
---|
| 81 | $odo->needle->SetLength(0.7); // Length as 70% of the radius
|
---|
| 82 | $odo->needle->SetFillColor("orange");
|
---|
| 83 |
|
---|
| 84 |
|
---|
| 85 | //---------------------------------------------------------------------
|
---|
| 86 | // Add the odometer to the graph
|
---|
| 87 | //---------------------------------------------------------------------
|
---|
| 88 | $graph->Add($odo);
|
---|
| 89 |
|
---|
| 90 | //---------------------------------------------------------------------
|
---|
| 91 | // ... and finally stroke and stream the image back to the browser
|
---|
| 92 | //---------------------------------------------------------------------
|
---|
| 93 | $graph->Stroke();
|
---|
| 94 |
|
---|
| 95 | // EOF
|
---|
| 96 | ?> |
---|