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

Last change on this file since 42 was 42, checked in by marrucho, 10 years ago
File size: 1.4 KB
Line 
1<?php // content="text/plain; charset=utf-8"
2require_once ('jpgraph/jpgraph.php');
3require_once ('jpgraph/jpgraph_line.php');
4require_once ('jpgraph/jpgraph_bar.php');
5
6function readsunspotdata($aFile, &$aYears, &$aSunspots) {
7    $lines = @file($aFile,FILE_IGNORE_NEW_LINES|FILE_SKIP_EMPTY_LINES);
8    if( $lines === false ) {
9        throw new JpGraphException('Can not read sunspot data file.');
10    }
11    foreach( $lines as $line => $datarow ) {
12        $split = preg_split('/[\s]+/',$datarow);
13        $aYears[] = substr(trim($split[0]),0,4);
14        $aSunspots[] = trim($split[1]);
15    }
16}
17
18$year = array();
19$ydata = array();
20readsunspotdata('yearssn.txt',$year,$ydata);
21
22 // Width and height of the graph
23$width = 600; $height = 200;
24
25// Create a graph instance
26$graph = new Graph($width,$height);
27
28// Specify what scale we want to use,
29// int = integer scale for the X-axis
30// int = integer scale for the Y-axis
31$graph->SetScale('intint');
32
33// Setup a title for the graph
34$graph->title->Set('Sunspot example');
35
36// Setup titles and X-axis labels
37$graph->xaxis->title->Set('(year from 1701)');
38$graph->xaxis->SetTickLabels($year);
39
40// Setup Y-axis title
41$graph->yaxis->title->Set('(# sunspots)');
42
43// Create the linear plot
44$lineplot=new LinePlot($ydata);
45$lineplot->SetFillColor('orange@0.5');
46
47// Add the plot to the graph
48$graph->Add($lineplot);
49
50// Display the graph
51$graph->Stroke();
52
53?>
Note: See TracBrowser for help on using the repository browser.