[ Index ]
 

Code source de jpGraph 2.2

Accédez au Source d'autres logiciels libres

title

Body

[fermer]

/src/Examples/ -> dateaxisex1.php (source)

   1  <?php
   2  include  ("../jpgraph.php");
   3  include  ("../jpgraph_line.php");
   4  
   5  // The callback that converts timestamp to minutes and seconds
   6  function TimeCallback($aVal) {
   7      return Date('H:i:s',$aVal);
   8  }
   9  
  10  // Fake some suitable random data
  11  $now = time();
  12  $datax = array($now);
  13  for( $i=0; $i < 360; $i += 10 ) {
  14      $datax[] = $now + $i;
  15  }
  16  $n = count($datax);
  17  $datay=array();
  18  for( $i=0; $i < $n; ++$i ) {
  19      $datay[] = rand(30,150);
  20  }
  21  
  22  // Setup the basic graph
  23  $graph = new Graph(324,250);
  24  $graph->SetMargin(40,40,30,70);    
  25  $graph->title->Set('Date: '.date('Y-m-d',$now));
  26  $graph->SetAlphaBlending();
  27  
  28  // Setup a manual x-scale (We leave the sentinels for the
  29  // Y-axis at 0 which will then autoscale the Y-axis.)
  30  // We could also use autoscaling for the x-axis but then it
  31  // probably will start a little bit earlier than the first value
  32  // to make the first value an even number as it sees the timestamp
  33  // as an normal integer value.
  34  $graph->SetScale("intlin",0,200,$now,$datax[$n-1]);
  35  
  36  // Setup the x-axis with a format callback to convert the timestamp
  37  // to a user readable time
  38  $graph->xaxis->SetLabelFormatCallback('TimeCallback');
  39  $graph->xaxis->SetLabelAngle(90);
  40  
  41  // Create the line
  42  $p1 = new LinePlot($datay,$datax);
  43  $p1->SetColor("blue");
  44  
  45  // Set the fill color partly transparent
  46  $p1->SetFillColor("blue@0.4");
  47  
  48  // Add lineplot to the graph
  49  $graph->Add($p1);
  50  
  51  // Output line
  52  $graph->Stroke();
  53  ?>
  54  
  55  


Généré le : Sat Nov 24 09:27:55 2007 par Balluche grâce à PHPXref 0.7
  Clicky Web Analytics