I am learning how to use the jpGraph library but when I use their example code I get a different result. 1 is their example and 2 is what my chart produces after I use the code they provided. I think the problem is for some reason the function they provided is just counting how many are in the 0(left) column instead of using the numbers. I am not sure what I did wrong. I have tried changing the right column with the left and it does the same thing.
require_once ('Libraries/jpgraph/jpgraph.php');
require_once ('Libraries/jpgraph/jpgraph_line.php');
require_once ('Libraries/jpgraph/jpgraph_bar.php');
function readsunspotdata($aFile, &$aYears, &$aSunspots) {
$lines = @file($aFile,FILE_IGNORE_NEW_LINES|FILE_SKIP_EMPTY_LINES);
if( $lines === false ) {
throw new JpGraphException('Can not read sunspot data file.');
}
foreach( $lines as $line => $datarow ) {
$split = preg_split('/[\s]+/',$datarow);
$aYears[] = substr(trim($split[0]),0,4);
$aSunspots[] = trim($split[1]);
}
}
$year = array();
$ydata = array();
readsunspotdata('yearssn.txt',$year,$ydata);
// Width and height of the graph
$width = 1000; $height = 500;
// Create a graph instance
$graph = new Graph($width,$height);
// Specify what scale we want to use,
// int = integer scale for the X-axis
// int = integer scale for the Y-axis
$graph->SetScale('intint');
// Setup a title for the graph
$graph->title->Set('Sunspot example');
// Setup titles and X-axis labels
$graph->xaxis->title->Set('(year from 1701)');
// Setup Y-axis title
$graph->yaxis->title->Set('(# sunspots)');
// Create the linear plot
$lineplot=new LinePlot($ydata);
// Add the plot to the graph
$graph->Add($lineplot);
// Display the graph
$graph->Stroke();
text file
1700.5 5.0
1701.5 11.0
1702.5 16.0
1703.5 23.0
1704.5 36.0
1705.5 58.0
1706.5 29.0
1707.5 20.0
1708.5 10.0
1709.5 8.0
17012.5 15.0