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

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