views:

12

answers:

1

Hi all,

I have remade my original post as it was terribly formatted. Basically I would like some advice / tips on how to generate a line graph with 2 Y Axis (temperature and humidity) to display some information from my text file. It is contained in a textfile called temperaturedata.txt I have included a link to one of my posts from the JpGrapher forum only because it is able to display the code clearly.

I understand that since it is JpGraph problem I shouldn't post here however the community here is a lot more supportive and active. Many thanks for all your help guys in advance!

my code

A: 

Hi. I don't see any reason why you shouldn't post here about jpgraph. And I don't see why you shouldn't post your sample code and data here, either.

The code you've posted on the other site is broken. Check line #42.

Furthermore, you're passing JpGraph a single row (specifically, the last row) via $keyval. $data is where all your data is stored, though in a wrong format. A very quick fix was:

$keyval = array();
$keyval['time'] = array();
$keyval['count'] = array();
$keyval['temperature'] = array();
$keyval['humidity'] = array();

if ($file) {
 while (!feof($file)) {
  $line = trim(fgets($file));
  if (strlen($line)) {
   $fields = explode(":", $line);
   $keyval['time'][]        = $fields[0];
   $keyval['count'][]       = $fields[1];
   $keyval['temperature'][] = $fields[2];
   $keyval['humidity'][]    = $fields[3];
  }
 }

 fclose($file);
}

which transposed $data and renamed it $keyval. (Where it used to hold time data in $data[x]['time'], it now holds it in $keyval['time'][x].) And we're passing $keyval['temperature'], which is a simple array of temperature values.

aib