source: trunk/xgraph/jpgraph/Examples/prepaccdata_example.php @ 42

Last change on this file since 42 was 42, checked in by marrucho, 10 years ago
File size: 1.6 KB
Line 
1<?php // content="text/plain; charset=utf-8"
2require_once ('../jpgraph.php');
3require_once ('../jpgraph_line.php');
4require_once ('../jpgraph_date.php');
5
6//Create some test data
7$xdata = array();
8$ydata = array();
9
10// Timestamps - 2h (=7200s) apart starting
11$sampling = 7200;
12$n = 50; // data points
13for($i=0; $i < $n; ++$i ) {
14    $xdata[$i] = time() + $i * $sampling;
15    $ydata[0][$i] = rand(12,15);
16    $ydata[1][$i] = rand(100,155);
17    $ydata[2][$i] = rand(20,30);
18}
19
20function formatDate(&$aVal) {
21    $aVal = date('Y-m-d H:i',$aVal);
22}
23
24// Apply this format to all time values in the data to prepare it to be display
25array_walk($xdata,'formatDate');
26
27// Create the graph.
28$graph  = new Graph(600, 350);
29$graph->title->Set('Accumulated values with specified X-axis scale');
30$graph->SetScale('textlin');
31
32// Setup margin color
33$graph->SetMarginColor('green@0.95');
34
35// Adjust the margin to make room for the X-labels
36$graph->SetMargin(40,30,40,120);
37
38// Turn the tick marks out from the plot area
39$graph->xaxis->SetTickSide(SIDE_BOTTOM);
40$graph->yaxis->SetTickSide(SIDE_LEFT);
41
42$p0 =new LinePlot($ydata[0]);
43$p0->SetFillColor('sandybrown');
44$p1 =new LinePlot($ydata[1]);
45$p1->SetFillColor('lightblue');
46$p2 =new LinePlot($ydata[2]);
47$p2->SetFillColor('red');
48$ap = new AccLinePlot(array($p0,$p1,$p2));
49
50$graph->xaxis->SetTickLabels($xdata);
51$graph->xaxis->SetTextLabelInterval(4);
52
53// Add the plot to the graph
54$graph->Add($ap);
55
56// Set the angle for the labels to 90 degrees
57$graph->xaxis->SetLabelAngle(90);
58
59// Display the graph
60$graph->Stroke();
61?>
Note: See TracBrowser for help on using the repository browser.