I have a 3 column tabbed file (date, value, value) that I parse to an array
which I use to plot a graph.
There are no tabs at the end each lines.
When I feed this array to SetDataValues() the result is no graph for the third
(last) column. Only for the first 2(?) values of the third column.
However when I add a tab to the end of each line (using sed), and I parse the
file the array is exactly the same.
But: I DO GET A GRAPH.
I am confused how can phplot create different results with the same arrays?
The file that are parsed are different (one has tabs eol and the other one
doesn't) but the arrays are exactly the same.
Hi, could you post the code you use to parse the tabbed file and build your
array? (Your links aren't helping because they are running as PHP scripts, I
guess.) You can just paste it into this forum thread in a "code" block. I
would like to take a look there first.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
OK, the main problem is that fgets() returns a line from the file including
the trailing newline. When you explode() that, the newline is still there, at
the end of the last (3rd) field. That goes into your data array. PHPlot tests
data values with is_numeric() to see if they are valid or should be skipped,
and is_numeric("100\n") is false so that point gets ignored.
Second problem is that testing with feof() at the top will result in one extra
record being read at the end, containing no data. You probably should be
testing the return from fgets() instead.
You can fix the first problem by exploding rtrim($line_of_text) instead of
$line_of_text.
Or, you can use different functions to read the file. Here are some code
snippets to read tab-separated values. But these read all fields on each line,
which is different from yours which only reads the first 3. So they won't be
usable to you if your file contains more columns that you want to ignore.
This uses file() to read the whole file. If you have a huge file, it may
Or, you can use fgetcsv() with delimiter "\t" to read the file. However this
will strip out double quotes unless you also set the 'enclosure' parameter to
something that never occurs in your file. For example:
Hi,
I have a 3 column tabbed file (date, value, value) that I parse to an array
which I use to plot a graph.
There are no tabs at the end each lines.
When I feed this array to SetDataValues() the result is no graph for the third
(last) column. Only for the first 2(?) values of the third column.
However when I add a tab to the end of each line (using sed), and I parse the
file the array is exactly the same.
But: I DO GET A GRAPH.
I am confused how can phplot create different results with the same arrays?
The file that are parsed are different (one has tabs eol and the other one
doesn't) but the arrays are exactly the same.
Arrays:
http://www.willempasterkamp.nl/tab.php
http://www.willempasterkamp.nl/tabeol.php
Graphs:
http://www.willempasterkamp.nl/tab.graph.php
http://www.willempasterkamp.nl/tabeol.graph.php
Cheers,
Jan
Hi, could you post the code you use to parse the tabbed file and build your
array? (Your links aren't helping because they are running as PHP scripts, I
guess.) You can just paste it into this forum thread in a "code" block. I
would like to take a look there first.
Hi Ibayuk,
here it is.
OK, the main problem is that fgets() returns a line from the file including
the trailing newline. When you explode() that, the newline is still there, at
the end of the last (3rd) field. That goes into your data array. PHPlot tests
data values with is_numeric() to see if they are valid or should be skipped,
and is_numeric("100\n") is false so that point gets ignored.
Second problem is that testing with feof() at the top will result in one extra
record being read at the end, containing no data. You probably should be
testing the return from fgets() instead.
You can fix the first problem by exploding rtrim($line_of_text) instead of
$line_of_text.
Or, you can use different functions to read the file. Here are some code
snippets to read tab-separated values. But these read all fields on each line,
which is different from yours which only reads the first 3. So they won't be
usable to you if your file contains more columns that you want to ignore.
This uses file() to read the whole file. If you have a huge file, it may
use more memory than you want.
Or, you can use fgetcsv() with delimiter "\t" to read the file. However this
will strip out double quotes unless you also set the 'enclosure' parameter to
something that never occurs in your file. For example:
The 0 is for no line length limit, \t is the delimiter, and 'enclosure'
argument is set to ASCII 1.
Wow thanks so much for your thorough explanation!
It makes sense now. Thanks a lot.