| 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 | $ydata = array();
 | 
|---|
| 12 | $xdata = array();
 | 
|---|
| 13 | 
 | 
|---|
| 14 | for( $i=0; $i < (NDATAPOINTS/1); ++$i ) {
 | 
|---|
| 15 |     $ydata[$i] = rand(50,70);
 | 
|---|
| 16 |     $xdata[$i] = $start + $i * SAMPLERATE;
 | 
|---|
| 17 |     //$xdata[$i] = time() + $i * SAMPLERATE;
 | 
|---|
| 18 |     //echo $xdata[$i]," \n";
 | 
|---|
| 19 |     //sleep(1);
 | 
|---|
| 20 | }
 | 
|---|
| 21 | 
 | 
|---|
| 22 | function maFormatDate(&$aVal) {
 | 
|---|
| 23 |     $aVal = date('Y-m-d H:i',$aVal);
 | 
|---|
| 24 | }
 | 
|---|
| 25 |  
 | 
|---|
| 26 | // Apply this format to all time values in the data to prepare it to be display
 | 
|---|
| 27 | array_walk($xdata,'maFormatDate');
 | 
|---|
| 28 |  
 | 
|---|
| 29 | // Create the new graph
 | 
|---|
| 30 | $graph = new Graph(600,450);
 | 
|---|
| 31 |  
 | 
|---|
| 32 | // Fix the Y-scale to go between [0,100] and use date for the x-axis
 | 
|---|
| 33 | $graph->SetScale('textlin',0,100);
 | 
|---|
| 34 | //$graph->SetScale('textlin');
 | 
|---|
| 35 | $graph->title->Set("Example on Date scale");
 | 
|---|
| 36 | 
 | 
|---|
| 37 | // Slightly larger than normal margins at the bottom to have room for
 | 
|---|
| 38 | // the x-axis labels
 | 
|---|
| 39 | $graph->SetMargin(40,40,30,130);
 | 
|---|
| 40 |  
 | 
|---|
| 41 | // Set the angle for the labels to 90 degrees
 | 
|---|
| 42 | $graph->xaxis->SetLabelAngle(90);
 | 
|---|
| 43 |  
 | 
|---|
| 44 | //$line = new LinePlot($data,$xdata);
 | 
|---|
| 45 | $line = new LinePlot($ydata);
 | 
|---|
| 46 | $line->SetLegend('Year 2013');
 | 
|---|
| 47 | $line->SetFillColor('lightred@0.8');
 | 
|---|
| 48 | 
 | 
|---|
| 49 | $graph->xaxis->SetTickLabels($xdata);
 | 
|---|
| 50 | $graph->xaxis->SetTextLabelInterval(NDATAPOINTS/10);
 | 
|---|
| 51 | 
 | 
|---|
| 52 | //$graph->Add($line);
 | 
|---|
| 53 | $line->SetColor('red');
 | 
|---|
| 54 | $graph->AddLine($line);
 | 
|---|
| 55 | 
 | 
|---|
| 56 | 
 | 
|---|
| 57 | $graph->Stroke();
 | 
|---|
| 58 | 
 | 
|---|
| 59 | ?>
 | 
|---|