| 1 | <?php // content="text/plain; charset=utf-8"
 | 
|---|
| 2 | require_once ('../jpgraph.php');
 | 
|---|
| 3 | require_once ('../jpgraph_line.php');
 | 
|---|
| 4 | require_once ('../jpgraph_date.php');
 | 
|---|
| 5 | 
 | 
|---|
| 6 | DEFINE('INTERVAL', 5*60);
 | 
|---|
| 7 | 
 | 
|---|
| 8 | // First create some "dummy" data
 | 
|---|
| 9 | $m = 5; // Number of data sets
 | 
|---|
| 10 | $n = 4; // Number of bids to show
 | 
|---|
| 11 | $startbid = 8000;
 | 
|---|
| 12 | 
 | 
|---|
| 13 | for( $i=0; $i < $m; ++$i ) {
 | 
|---|
| 14 |     $bids[$i] = array($startbid + rand(100,500)*10 );
 | 
|---|
| 15 |     for( $j=1; $j < $n; ++$j ) {
 | 
|---|
| 16 |         $bids[$i][$j] = $bids[$i][$j-1] + rand(20,500)*10;
 | 
|---|
| 17 |     }
 | 
|---|
| 18 | }
 | 
|---|
| 19 | 
 | 
|---|
| 20 | $start = floor(time()/INTERVAL)*INTERVAL;
 | 
|---|
| 21 | $times = array($start);
 | 
|---|
| 22 | for( $i=1; $i < $n; ++$i ) {
 | 
|---|
| 23 |     // Create a timestamp for every 5 minutes
 | 
|---|
| 24 |     $times[$i] = $times[$i-1]+INTERVAL;
 | 
|---|
| 25 | }
 | 
|---|
| 26 | 
 | 
|---|
| 27 | // Setup the bid graph
 | 
|---|
| 28 | $graph = new Graph(600,250);
 | 
|---|
| 29 | $graph->SetMargin(80,30,50,40);
 | 
|---|
| 30 | $graph->SetMarginColor('white');
 | 
|---|
| 31 | $graph->SetScale('dateint');
 | 
|---|
| 32 | $graph->title->Set('Current Bids');
 | 
|---|
| 33 | $graph->title->SetFont(FF_ARIAL,FS_BOLD,12);
 | 
|---|
| 34 | $graph->subtitle->Set('(Updated every 5 minutes)');
 | 
|---|
| 35 | $graph->subtitle->SetFont(FF_ARIAL,FS_ITALIC,10);
 | 
|---|
| 36 | 
 | 
|---|
| 37 | // Enable antialias
 | 
|---|
| 38 | $graph->img->SetAntiAliasing();
 | 
|---|
| 39 | 
 | 
|---|
| 40 | // Setup the y-axis to show currency values
 | 
|---|
| 41 | $graph->yaxis->SetLabelFormatCallback('number_format');
 | 
|---|
| 42 | $graph->yaxis->SetLabelFormat('$%s');
 | 
|---|
| 43 | 
 | 
|---|
| 44 | //Use hour:minute format for the labels
 | 
|---|
| 45 | $graph->xaxis->scale->SetDateFormat('H:i');
 | 
|---|
| 46 | 
 | 
|---|
| 47 | // Force labels to only be displayed every 5 minutes
 | 
|---|
| 48 | $graph->xaxis->scale->ticks->Set(INTERVAL);
 | 
|---|
| 49 | 
 | 
|---|
| 50 | // Adjust the start time for an "even" 5 minute, i.e. 5,10,15,20,25, ...
 | 
|---|
| 51 | $graph->xaxis->scale->SetTimeAlign(MINADJ_5);
 | 
|---|
| 52 | 
 | 
|---|
| 53 | // Create the plots using the dummy data created at the beginning
 | 
|---|
| 54 | $line = array();
 | 
|---|
| 55 | for( $i=0; $i < $m; ++$i ) {
 | 
|---|
| 56 |     $line[$i] = new LinePlot($bids[$i],$times);
 | 
|---|
| 57 |     $line[$i]->mark->SetType(MARK_SQUARE);
 | 
|---|
| 58 | }
 | 
|---|
| 59 | $graph->Add($line);
 | 
|---|
| 60 | 
 | 
|---|
| 61 | // Send the graph back to the client
 | 
|---|
| 62 | $graph->Stroke();
 | 
|---|
| 63 | ?>
 | 
|---|