[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 | //
|
---|
| 40 | // We use an integer scale on the X-axis since the positions on the X axis
|
---|
| 41 | // are assumed to be UNI timestamps
|
---|
| 42 | $graph->SetScale('linlin',0,0,$xmin,$xmax);
|
---|
| 43 | $graph->title->Set('Example with manual tick labels');
|
---|
| 44 | $graph->title->SetFont(FF_ARIAL,FS_NORMAL,12);
|
---|
| 45 |
|
---|
| 46 | //
|
---|
| 47 | // Make sure that the X-axis is always at the bottom of the scale
|
---|
| 48 | // (By default the X-axis is alwys positioned at Y=0 so if the scale
|
---|
| 49 | // doesn't happen to include 0 the axis will not be shown)
|
---|
| 50 | $graph->xaxis->SetPos('min');
|
---|
| 51 |
|
---|
| 52 | // Now set the tic positions
|
---|
| 53 | $graph->xaxis->SetMajTickPositions($tickPositions,$tickLabels);
|
---|
| 54 |
|
---|
| 55 | // Use Times font
|
---|
| 56 | $graph->xaxis->SetFont(FF_TIMES,FS_NORMAL,10);
|
---|
| 57 | $graph->yaxis->SetFont(FF_TIMES,FS_NORMAL,10);
|
---|
| 58 |
|
---|
| 59 | // Add a X-grid
|
---|
| 60 | $graph->xgrid->Show();
|
---|
| 61 |
|
---|
| 62 | // Create the plot line
|
---|
| 63 | $p1 = new LinePlot($datay,$datax);
|
---|
| 64 | $p1->SetColor('teal');
|
---|
| 65 | $graph->Add($p1);
|
---|
| 66 |
|
---|
| 67 | // Output graph
|
---|
| 68 | $graph->Stroke();
|
---|
| 69 |
|
---|
| 70 | ?>
|
---|
| 71 |
|
---|
| 72 |
|
---|