[42] | 1 | <?php // content="text/plain; charset=utf-8"
|
---|
| 2 | //
|
---|
| 3 | // Basic example on how to use custom tickmark feature to have a label
|
---|
| 4 | // at the start of each month.
|
---|
| 5 | //
|
---|
| 6 | require_once ('jpgraph/jpgraph.php');
|
---|
| 7 | require_once ('jpgraph/jpgraph_line.php');
|
---|
| 8 | require_once ('jpgraph/jpgraph_utils.inc.php');
|
---|
| 9 |
|
---|
| 10 | //
|
---|
| 11 | // Create some random data for the plot. We use the current time for the
|
---|
| 12 | // first X-position
|
---|
| 13 | //
|
---|
| 14 | $f = new FuncGenerator('cos($x)+1.5*cos(2*$x)');
|
---|
| 15 | list($datax,$datay) = $f->E(0,10);
|
---|
| 16 |
|
---|
| 17 | // Now get labels at 1/2 PI intervall
|
---|
| 18 | $tickPositions = array();
|
---|
| 19 | $tickLabels = array();
|
---|
| 20 | $tickPositions[0] = 0;
|
---|
| 21 | $tickLabels[0] = '0';
|
---|
| 22 | for($i=1; $i/2*M_PI < 11 ; ++$i ) {
|
---|
| 23 | $tickPositions[$i] = $i/2*M_PI;
|
---|
| 24 | if( $i % 2 )
|
---|
| 25 | $tickLabels[$i] = $i.'/2'.SymChar::Get('pi');
|
---|
| 26 | else
|
---|
| 27 | $tickLabels[$i] = ($i/2).SymChar::Get('pi');
|
---|
| 28 | }
|
---|
| 29 |
|
---|
| 30 | $n = count($datax);
|
---|
| 31 | $xmin = $datax[0];
|
---|
| 32 | $xmax = $datax[$n-1];
|
---|
| 33 |
|
---|
| 34 | //
|
---|
| 35 | // The code to setup a very basic graph
|
---|
| 36 | //
|
---|
| 37 | $graph = new Graph(400,200);
|
---|
| 38 |
|
---|
| 39 | // We use an integer scale on the X-axis since the positions on the X axis
|
---|
| 40 | // are assumed to be UNI timestamps
|
---|
| 41 | $graph->SetScale('linlin',0,0,$xmin,$xmax);
|
---|
| 42 | $graph->title->Set('Example with manual tick labels');
|
---|
| 43 | $graph->title->SetFont(FF_ARIAL,FS_BOLD,12);
|
---|
| 44 | $graph->title->SetColor('white');
|
---|
| 45 |
|
---|
| 46 | // Setup a abackground gradient
|
---|
| 47 | $graph->SetBackgroundGradient('darkred:0.7', 'black', 2, BGRAD_MARGIN);
|
---|
| 48 | $graph->SetPlotGradient('black','darkred:0.8', 2);
|
---|
| 49 |
|
---|
| 50 | // Make sure that the X-axis is always at the bottom of the scale
|
---|
| 51 | // (By default the X-axis is alwys positioned at Y=0 so if the scale
|
---|
| 52 | // doesn't happen to include 0 the axis will not be shown)
|
---|
| 53 | $graph->xaxis->SetPos('min');
|
---|
| 54 |
|
---|
| 55 | // Now set the tic positions
|
---|
| 56 | $graph->xaxis->SetMajTickPositions($tickPositions,$tickLabels);
|
---|
| 57 |
|
---|
| 58 | // Use Times font
|
---|
| 59 | $graph->xaxis->SetFont(FF_TIMES,FS_NORMAL,11);
|
---|
| 60 | $graph->yaxis->SetFont(FF_TIMES,FS_NORMAL,9);
|
---|
| 61 |
|
---|
| 62 | // Set colors for axis
|
---|
| 63 | $graph->xaxis->SetColor('lightgray');
|
---|
| 64 | $graph->yaxis->SetColor('lightgray');
|
---|
| 65 |
|
---|
| 66 | // Add a X-grid
|
---|
| 67 | $graph->xgrid->Show();
|
---|
| 68 |
|
---|
| 69 | // Show ticks outwards
|
---|
| 70 | $graph->xaxis->SetTickSide(SIDE_DOWN);
|
---|
| 71 | $graph->xaxis->SetLabelMargin(8);
|
---|
| 72 | $graph->yaxis->SetTickSide(SIDE_LEFT);
|
---|
| 73 |
|
---|
| 74 | // Setup a filled y-grid
|
---|
| 75 | //$graph->ygrid->SetFill(true,'darkgray:1.55@0.7','darkgray:1.6@0.7');
|
---|
| 76 | $graph->ygrid->SetStyle('dotted');
|
---|
| 77 | $graph->xgrid->SetStyle('dashed');
|
---|
| 78 |
|
---|
| 79 | // Create the plot line
|
---|
| 80 | $p1 = new LinePlot($datay,$datax);
|
---|
| 81 | $p1->SetWeight(2);
|
---|
| 82 | $p1->SetColor('orange:0.9');
|
---|
| 83 | $p1->SetFillColor('white@0.7');
|
---|
| 84 | $p1->SetFillFromYMin();
|
---|
| 85 | $graph->Add($p1);
|
---|
| 86 |
|
---|
| 87 | // Output graph
|
---|
| 88 | $graph->Stroke();
|
---|
| 89 |
|
---|
| 90 | ?>
|
---|
| 91 |
|
---|
| 92 |
|
---|