I'm getting the error message "array_values() expects parameter 1 to be array,
null given in /phplot.php on line 2499" when I call
$plot->SetDataValues($data)
If I suppress using a leading '@' ahead of the $plot... the process does plot.
I'm suspecting some kind of error when I'm building the $data array, but what
should I look for?
Thanks.
DN
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I'm working on getting PHPlot to respond better to data array errors (see
other thread here), but it probably won't catch everything. The message you
are seeing from SetDataValues() most likely means one of the rows of your data
array is NULL, rather than being an array. (Unless you also got a message just
before that about an undefined offset. That would mean your data array isn't
an integer indexed, 0 based array.)
Example of a bad data array which will produce just that array_values expects
... null given error:
One way to debug this is to insert something like print_r($data); exit(1);
after the data error is built, then run the script directly (CLI is best) and
see what is the array really looks like. The outer array needs to be 0-based,
sequential integer indexed, with each value being an array representing a row.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Forgot to say: In the second example above, the first message (undefined
offset) is a Notice, and the second (array_values expectes) is a Warning. If
your PHP is configured to not show Notice messages, you won't see the first
one, so you won't be able to tell the two cases apart.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I truncated the time sequence and the problem disappeared. There are two
possible explanations, the first is that I excluded a problem data point, the
second is that I avoided the "time wrap" problem I described in my other
message. So I checked the full data set for nulls, and it is fine, no
defective entries.
That leaves the "time wrap" as a possible explanation. For a data and a time
array, the time goes from approx 20:30:00 to 03:00:00 the following day. The
arrays are in normal time sequence. When I plot data vs time, the time values
are displayed in numerical sequence with the "previous day" ("higher") values
plotted later than the "current day". The axis is continuous starting at
00:00:00 but the data is broken and wrapped. How do I avoid this?
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Glad it is working. The next release of PHPlot will do more checking on the
data array, and report errors either when SetDataValues() is called, or when
DrawGraph() is called. (Some checking can't be done until the data type is
set, and SetDataValues can't assume that was already done.) The goal is to
avoid PHP warnings and notices if the data array is not valid, and make it
easier to identify and fix the problem. I just hope it doesn't break any
existing plots that were somehow working with a bad data array.
Headers in CSV files are good - I like using them for documentation of the
data. But of course you have to take that into account when processing it.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I'm getting the error message "array_values() expects parameter 1 to be array,/phplot.php on line 2499" when I call
null given in
$plot->SetDataValues($data)
If I suppress using a leading '@' ahead of the $plot... the process does plot.
I'm suspecting some kind of error when I'm building the $data array, but what
should I look for?
Thanks.
DN
I'm working on getting PHPlot to respond better to data array errors (see
other thread here), but it probably won't catch everything. The message you
are seeing from SetDataValues() most likely means one of the rows of your data
array is NULL, rather than being an array. (Unless you also got a message just
before that about an undefined offset. That would mean your data array isn't
an integer indexed, 0 based array.)
Example of a bad data array which will produce just that array_values expects
... null given error:
Example of a bad data array which will produce an undefined offset _ error,
then _array_values expects ... null given error:
One way to debug this is to insert something like print_r($data); exit(1);
after the data error is built, then run the script directly (CLI is best) and
see what is the array really looks like. The outer array needs to be 0-based,
sequential integer indexed, with each value being an array representing a row.
Forgot to say: In the second example above, the first message (undefined
offset) is a Notice, and the second (array_values expectes) is a Warning. If
your PHP is configured to not show Notice messages, you won't see the first
one, so you won't be able to tell the two cases apart.
I truncated the time sequence and the problem disappeared. There are two
possible explanations, the first is that I excluded a problem data point, the
second is that I avoided the "time wrap" problem I described in my other
message. So I checked the full data set for nulls, and it is fine, no
defective entries.
That leaves the "time wrap" as a possible explanation. For a data and a time
array, the time goes from approx 20:30:00 to 03:00:00 the following day. The
arrays are in normal time sequence. When I plot data vs time, the time values
are displayed in numerical sequence with the "previous day" ("higher") values
plotted later than the "current day". The axis is continuous starting at
00:00:00 but the data is broken and wrapped. How do I avoid this?
It's all working nicely now. I think I may have done something stupid, like
loading a csv file that had a header line. (Doh!)
Glad it is working. The next release of PHPlot will do more checking on the
data array, and report errors either when SetDataValues() is called, or when
DrawGraph() is called. (Some checking can't be done until the data type is
set, and SetDataValues can't assume that was already done.) The goal is to
avoid PHP warnings and notices if the data array is not valid, and make it
easier to identify and fix the problem. I just hope it doesn't break any
existing plots that were somehow working with a bad data array.
Headers in CSV files are good - I like using them for documentation of the
data. But of course you have to take that into account when processing it.