When using the RGraph CSV reader to read from a database, negative values are not processed properly

« Back to message list

Enter your email address to get email updates on this topic. You can stop receiving updates by clicking the link in the update email messages.

Posted by Stephan on 7th February 2014
I am using a few graphs to update every 5 minutes with new data from the database. But it seems that negative values are not being process and looks like they are being nulled.

The key graph is temperature which include normal temp, dew point and windchill. I had today that the windchill went below 0 and suddenly no line was being drawn on the graph.
If I compare it with my other graphs (monthly) which gets its data directly created via PHP (instead of importing via CSV) it does work with negative values.

The unique thing is that I calculate the minimum value if windchill and use that for ymin value, and the graph does show on the y axis -2.

You can find the graphs on io-node.net/weather2/12hours.php
Direct access to the CSV generator is: io-node.net/weather2/12hr_temperature.php

Posted by Richard on 7th February 2014
Hi there,

It's a small bug in the CSV parsing - if you're comfortable changing the code then find the line around 103 that looks like this:

if ((/^[0-9.]+$/).test(row[j])) {

and replace it with this:

if ((/^\-?[0-9.]+$/).test(row[j])) {

Posted by Stephan on 9th February 2014
Hi Richard,

Thanks for that fix. In the meantime I use the following to get it to work:

for (var i=0; i<windchill.length; ++i) {
   windchill[i] = parseFloat(windchill[i]);

But reverted now to work with the fix.



Add a reply

« Back to message list