I tried to generate a line plot using jpgraph. It works well when array is specified manually. But when I tired to receive data from csv file, only plot is generated, but data lines not shown. I couldnt find anything wrong in my input and in display the values on printing array,
print_r ($data[2]); printing displays Array ( [1] => 22.7625 [2] => 7.1984)
Searching the manual didn't solve my problem. Anyone know the reason?
Info: Here is how I have extracted data from csv file,
$handle = fopen("/var/www/html/xx/yy/myfile.csv", "r");
$data[$i] = fgetcsv($handle, ",");
I removed the first element since it is an ID.
unset($data[2] [0]);
Edit:
<?php
include ( "../jpgraph.php");
include ("../jpgraph_line.php");
$handle = fopen("/var/www/html/xx/yy/myfile.csv", "r");
for ($i=0;$i<=10;$i++)
{
$data[$i] = fgetcsv($handle, ",");
unset($data[2] [0]);
}
$graph = new Graph(350, 250,"auto");
$graph->SetScale( "textlin");
$lineplot =new LinePlot($data[2]);
$lineplot ->SetColor("blue");
$graph->Add( $lineplot);
$graph->Stroke();
?>
Although I can't explain why, unset() is not your friend here.
Here's an example that strips off the first element of each line from the csv file and plots the next three elements. It does work. And thanks for introducing me to JPGraph.
<?php
include "jpgraph.php";
include "jpgraph_line.php";
$handle = fopen("mike.csv", "r");
for ($i=0;$i<=10;$i++)
{
$temp = fgetcsv($handle, ",");
// $temp[0] is ignored
$data[$i][0] = $temp[1];
$data[$i][1] = $temp[2];
$data[$i][2] = $temp[3];
}
$graph = new Graph(350, 250);
$graph->SetScale( "textlin");
$lineplot =new LinePlot($data[2]);
$lineplot ->SetColor("blue");
$graph->Add( $lineplot);
$graph->Stroke();
?>