source: trunk/xgraph/jpgraph/Examples/dateaxisex1.php

Last change on this file was 42, checked in by marrucho, 10 years ago
File size: 1.5 KB
Line 
1<?php // content="text/plain; charset=utf-8"
2require_once ('jpgraph/jpgraph.php');
3require_once ('jpgraph/jpgraph_line.php');
4
5// The callback that converts timestamp to minutes and seconds
6function TimeCallback($aVal) {
7    return Date('H:i:s',$aVal);
8}
9
10// Fake some suitable random data
11$now = time();
12$datax = array($now);
13for( $i=0; $i < 360; $i += 10 ) {
14    $datax[] = $now + $i;
15}
16$n = count($datax);
17$datay=array();
18for( $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
Note: See TracBrowser for help on using the repository browser.