[42] | 1 | <?php // content="text/plain; charset=utf-8"
|
---|
| 2 | require_once ('jpgraph/jpgraph.php');
|
---|
| 3 | require_once ('jpgraph/jpgraph_line.php');
|
---|
| 4 | require_once ('jpgraph/jpgraph_date.php');
|
---|
| 5 |
|
---|
| 6 | // Create a data set in range (50,70) and X-positions
|
---|
| 7 | DEFINE('NDATAPOINTS',360);
|
---|
| 8 | DEFINE('SAMPLERATE',240);
|
---|
| 9 | $start = time();
|
---|
| 10 | $end = $start+NDATAPOINTS*SAMPLERATE;
|
---|
| 11 | $data = array();
|
---|
| 12 | $xdata = array();
|
---|
| 13 | for( $i=0; $i < NDATAPOINTS; ++$i ) {
|
---|
| 14 | $data[$i] = rand(50,70);
|
---|
| 15 | $xdata[$i] = $start + $i * SAMPLERATE;
|
---|
| 16 | }
|
---|
| 17 |
|
---|
| 18 |
|
---|
| 19 | // Create the new graph
|
---|
| 20 | $graph = new Graph(540,300);
|
---|
| 21 |
|
---|
| 22 | // Slightly larger than normal margins at the bottom to have room for
|
---|
| 23 | // the x-axis labels
|
---|
| 24 | $graph->SetMargin(40,40,30,130);
|
---|
| 25 |
|
---|
| 26 | // Fix the Y-scale to go between [0,100] and use date for the x-axis
|
---|
| 27 | $graph->SetScale('datlin',0,100);
|
---|
| 28 | $graph->title->Set("Example on Date scale");
|
---|
| 29 |
|
---|
| 30 | // Set the angle for the labels to 90 degrees
|
---|
| 31 | $graph->xaxis->SetLabelAngle(90);
|
---|
| 32 |
|
---|
| 33 | // It is possible to adjust the density for the X-axis as well
|
---|
| 34 | // The following call makes the dates a little more sparse
|
---|
| 35 | // $graph->SetTickDensity(TICKD_NORMAL,TICKD_SPARSE);
|
---|
| 36 |
|
---|
| 37 | // The automatic format string for dates can be overridden
|
---|
| 38 | // $graph->xaxis->scale->SetDateFormat('h:i');
|
---|
| 39 |
|
---|
| 40 | // Adjust the start/end to a specific alignment
|
---|
| 41 | $graph->xaxis->scale->SetTimeAlign(MINADJ_15);
|
---|
| 42 |
|
---|
| 43 | $line = new LinePlot($data,$xdata);
|
---|
| 44 | $line->SetLegend('Year 2005');
|
---|
| 45 | $line->SetFillColor('lightblue@0.5');
|
---|
| 46 | $graph->Add($line);
|
---|
| 47 | $graph->Stroke();
|
---|
| 48 | ?>
|
---|