Data that uses the YYYY-MM-DD format for a Scatter chart only works in Chrome

« 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 Dan on 4th June 2013
I have a db table with date/time format YYYY-MM-DD and when passed to the scatter chart, the line is only visible in Chrome. Safari, FF, and IE just show the grid without points or line.
The Scatter chart date/time example says that format is accepted, but of the four formats listed, it is the only one that does not work. Will I need to parse the date myself, or is this an easy fix on your end?

Posted by RGraph support on 5th June 2013
Hi there,

To parse dates RGraph uses the JavaScript Date.parse() function. - which supports the format YYYY-MM-DD (no time parameter).

Posted by Dan on 8th June 2013

Thought I sent a reply a few days ago, but thanks for getting back to me. I should have been more specific in that I need to pass the date and time in this format: YYYY-MM-DD HH:MM:SS. I followed the link listed at the bottom of the:

And it says "the date/time string may be in ISO 8601 format. Starting with JavaScript 1.8.5 (Firefox 4), a subset of ISO 8601 is supported. For example, "2011-10-10" (just date) or "2011-10-10T14:48:00" (date and time) can be passed and parsed."
I tried putting in the T between the date and time and still no luck, except Chrome. Is there something that can be done about this, or will I need to change my DB structure and all related code?


P.S. it still says that this format with the time parameter is accepted at the bottom of your page (sans seconds)
Posted by RGraph support on 8th June 2013
Hi there,

This format works: 2012-12-31T20:10:10
Note the 'T' instead of a space.

And thinking that you have to change your database structure is rather extreme - simply format that data that you retrieve from the database. Eg:

// Assume that the str is in the format: "2012-01-01 15:12:23"
function myFormatDate(str)
     // Format the date
     return str.replace(/ /, 'T');

Richard, RGraph Support
Posted by Dan on 13th June 2013
I tried placing the T in between, I mentioned this already in my post. That format is not working in IE, Safari, or Firefox, it only works in Chrome.
Here is my code:

$senquery = "SELECT `D`, `T`, `Se` FROM Node_1 WHERE CONCAT(`D`,' ',`T`) >= '$start_date' AND CONCAT(`D`,' ',`T`) <= '$end_date'";
$senresult = mysql_query($senquery);
if($senquery) {
  $senscatter = array();
  while($row = mysql_fetch_assoc($senresult)) {
   $senscatter[] = "\n" . "[" . "'" . date('Y/m/d', strtotime($row['D'])) . " " . $row['T'] . "', " . $row['Se'] . "]";
  $senscatter_string = "[" . join(", ", $senscatter) . "]";
  } else {
         print('MySQL query failed with error: ' . mysql_error());
//Convert sensor value to string
$sensor_string = $sensor;


  //window.onload = function ()
         var scatter = new RGraph.Scatter('level', <?php print($senscatter_string) ?>);
         // Set the start value to be the beginning of the day. If they're omitted time values default to 00:00:00
         scatter.Set('chart.xmin', '<?php print($start_date) ?>');

         // Set the end value to the end of the year
         scatter.Set('chart.xmax', '<?php print($end_date) ?>');
  scatter.Set('chart.ymax', 186);
  scatter.Set('chart.labels', ['<?php print($start_date)?>', ' ', ' ', ' ', ' ', '<?php print($half_date)?>', ' ', ' ',' ', ' ', '<?php print($end_date)?>']);
         scatter.Set('chart.line', true);
         scatter.Set('chart.line.colors', ['gray']);
         scatter.Set('chart.tickmarks', 'circle');
  scatter.Set('chart.title', 'Tank Level History');
  scatter.Set('chart.gutter.right', (.15*winW));



Any suggestions to have it work in a browser other than Chrome?
Posted by RGraph support on 13th June 2013
Hi there,

You don't appear to be using the correct format - the page here uses the format for the last point - only Safari doesn't appear to support this format:

Posted by Dan on 14th June 2013
That's ok, I was able to figure it out, just needed to manipulate the database query to get the necessary format. Thanks again for your help

Add a reply

« Back to message list