Possible bug with column type format validation?

54 views
Skip to first unread message

Wes Melton

unread,
Jun 6, 2018, 4:50:17 PM6/6/18
to Google Visualization API
Trying to dynamically build a line chart using the Google Charts API. 

This is the error being returned: 

`Value 2018-05-06T11:15:00-0400 does not match type datetime in column index`

Without even looking at code, the error message is super confusing as that is the ISO8601 format described in the documentation here: https://developers.google.com/chart/interactive/docs/datesandtimes

Here is the code building the chart: 

var data = new google.visualization.DataTable();

      for (var i = 0; i < chartData['cols'].length; i++) {
        data.addColumn(chartData['cols'][i].type, chartData['cols'][i].id);
      }

      for (var i = 0; i < chartData['rows'].length; i++) {
        data.addRow(chartData['rows'][i]);
      }

      var view = new google.visualization.DataView(data);


Here is a sample of chartData: 

chartData = {
"cols":[
{"id":"created_dt","type":"datetime"},
{"id":"Label 123","type":"number"},
{"id":"Label 124","type":"number"},
{"id":"Label 125","type":"number"},
{"id":"Label 126","type":"number"},
{"id":"Label 127","type":"number"}
],
"rows":[
["2018-05-06T11:15:00-0400",0.10,0.0,10,0.10,0.12],
["2018-05-06T11:30:00-0400",0.40,0,0.14,0.01,0.17],
["2018-05-06T11:45:00-0400",0.33,0,0.38,0.08,0.20],
["2018-05-06T12:00:00-0400",0.33,0,0.56,0.10,0.23],
["2018-05-06T12:15:00-0400",0.23,0,0.64,0.07,0.33]
]
}

Any help on what I'm doing wrong here would be much appreciated.

Daniel LaLiberte

unread,
Jun 6, 2018, 5:00:16 PM6/6/18
to Google Visualization API
Your data looks like datetimes, but it is really strings.  We don't parse the strings, except for a string of the form "Date(yyyy, mm, dd, ...)", which is intended for use in JSON strings.  If you are not restricted by JSON rules, you can generate the JavaScript constructor instead, e.g. new Date(2018, 4, 6, 11, 15, 0).  Note that months start at 0.

--
You received this message because you are subscribed to the Google Groups "Google Visualization API" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-visualizati...@googlegroups.com.
To post to this group, send email to google-visua...@googlegroups.com.
Visit this group at https://groups.google.com/group/google-visualization-api.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-visualization-api/a4eeb226-f294-4681-b664-261cba3c7640%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


--

Wes Melton

unread,
Jun 6, 2018, 5:12:27 PM6/6/18
to google-visua...@googlegroups.com
Data is coming from a PHP server.

If a constructor is passed as a literal string in the output from the PHP server, you are saying the library will parse it?


From: 'Daniel LaLiberte' via Google Visualization API <google-visua...@googlegroups.com>
Sent: Wednesday, June 6, 2018 4:59:39 PM
To: Google Visualization API
Subject: Re: [visualization-api] Possible bug with column type format validation?
 

Daniel LaLiberte

unread,
Jun 6, 2018, 5:14:22 PM6/6/18
to Google Visualization API
If you can pass a constructor to a place where JavaScript interprets it, then JavaScript will interpret it.  The "Date(...)" form is parsed by Google Charts, as if it were a constructor, even though it is a string.


For more options, visit https://groups.google.com/d/optout.

Wes Melton

unread,
Jun 6, 2018, 8:22:04 PM6/6/18
to google-visua...@googlegroups.com
Hi Daniel,

Taking your suggestion, we've modified the output to send a string with a new Date constructor in to the Graph API, but now the error is saying: 

"Error: Type mismatch. Value Date(2018,05,06,11,15) does not match type datetime in column index 0"

Example array: 

["new Date(2018,05,06,11,15)", 0.1, 0.11, 0.09, 0.13, 0.13]

We tried it without the 'new' verb (e.g. "Date(2018,05,06,11,15)" and that didn't work either. 

Scratching our heads here a little bit.


On Wed, Jun 6, 2018 at 5:13 PM, 'Daniel LaLiberte' via Google Visualization API <google-visua...@googlegroups.com> wrote:
If you can pass a constructor to a place where JavaScript interprets it, then JavaScript will interpret it.  The "Date(...)" form is parsed by Google Charts, as if it were a constructor, even though it is a string.

On Wed, Jun 6, 2018 at 5:12 PM Wes Melton <w...@smokymountains.com> wrote:
Data is coming from a PHP server.

If a constructor is passed as a literal string in the output from the PHP server, you are saying the library will parse it?


From: 'Daniel LaLiberte' via Google Visualization API <google-visualization-api@googlegroups.com>
To unsubscribe from this group and stop receiving emails from it, send an email to google-visualization-api+unsub...@googlegroups.com.
To post to this group, send email to google-visualization-api@googlegroups.com.


--
dlaliberte@Google.com   5CC, Cambridge MA

--
You received this message because you are subscribed to the Google Groups "Google Visualization API" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-visualization-api+unsub...@googlegroups.com.
To post to this group, send email to google-visualization-api@googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "Google Visualization API" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-visualization-api+unsub...@googlegroups.com.
To post to this group, send email to google-visualization-api@googlegroups.com.


--

--
You received this message because you are subscribed to the Google Groups "Google Visualization API" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-visualization-api+unsub...@googlegroups.com.
To post to this group, send email to google-visualization-api@googlegroups.com.

Daniel LaLiberte

unread,
Jun 6, 2018, 9:53:35 PM6/6/18
to Google Visualization API
Leave the "new " off of the string and it should work better.

On Wed, Jun 6, 2018 at 8:22 PM Wes Melton <w...@smokymountains.com> wrote:
Hi Daniel,

Taking your suggestion, we've modified the output to send a string with a new Date constructor in to the Graph API, but now the error is saying: 

"Error: Type mismatch. Value Date(2018,05,06,11,15) does not match type datetime in column index 0"

Example array: 

["new Date(2018,05,06,11,15)", 0.1, 0.11, 0.09, 0.13, 0.13]

We tried it without the 'new' verb (e.g. "Date(2018,05,06,11,15)" and that didn't work either. 

Scratching our heads here a little bit.

On Wed, Jun 6, 2018 at 5:13 PM, 'Daniel LaLiberte' via Google Visualization API <google-visua...@googlegroups.com> wrote:
If you can pass a constructor to a place where JavaScript interprets it, then JavaScript will interpret it.  The "Date(...)" form is parsed by Google Charts, as if it were a constructor, even though it is a string.

On Wed, Jun 6, 2018 at 5:12 PM Wes Melton <w...@smokymountains.com> wrote:
Data is coming from a PHP server.

If a constructor is passed as a literal string in the output from the PHP server, you are saying the library will parse it?


From: 'Daniel LaLiberte' via Google Visualization API <google-visua...@googlegroups.com>
To unsubscribe from this group and stop receiving emails from it, send an email to google-visualizati...@googlegroups.com.
To post to this group, send email to google-visua...@googlegroups.com.


--
dlaliberte@Google.com   5CC, Cambridge MA

--
You received this message because you are subscribed to the Google Groups "Google Visualization API" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-visualizati...@googlegroups.com.
To post to this group, send email to google-visua...@googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "Google Visualization API" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-visualizati...@googlegroups.com.
To post to this group, send email to google-visua...@googlegroups.com.


--

--
You received this message because you are subscribed to the Google Groups "Google Visualization API" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-visualizati...@googlegroups.com.
To post to this group, send email to google-visua...@googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "Google Visualization API" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-visualizati...@googlegroups.com.
To post to this group, send email to google-visua...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

Daniel LaLiberte

unread,
Jun 6, 2018, 10:02:29 PM6/6/18
to Google Visualization API
I think the problem is that you are mixing table formats.  

"rows":[
["2018-05-06T11:15:00-0400",0.10,0.0,10,0.10,0.12],
  ...
That won't work because the structure is unexpected.  It would need to be more like:
rows: [
          {c: [{v: 'Baltimore Ravens'},     {v: 'Date(2000, 8, 5)'}, {v: 'Date(2001, 1, 5)'}]},
as documented here:


Note that each row is an object with 'c' property.

Wes Melton

unread,
Jun 6, 2018, 10:07:47 PM6/6/18
to google-visua...@googlegroups.com
In the example given in the Line Chart documentation, it shows that you can use the helper methods (addColumn & addRow) instead of creating a formal datatable. 

   var data = new google.visualization.DataTable();

      data
.addColumn('number', 'Day');
      data
.addColumn('number', 'Guardians of the Galaxy');
      data
.addColumn('number', 'The Avengers');
      data
.addColumn('number', 'Transformers: Age of Extinction');

      data
.addRows([
       
[1,  37.8, 80.8, 41.8],
       
[2,  30.9, 69.5, 32.4],
       
[3,  25.4,   57, 25.7],
       
[4,  11.7, 18.8, 10.5],
       
[5,  11.9, 17.6, 10.4],
       
[6,   8.8, 13.6,  7.7],
       
[7,   7.6, 12.3,  9.6],
       
[8,  12.3, 29.2, 10.6],
       
[9,  16.9, 42.9, 14.8],
       
[10, 12.8, 30.9, 11.6],
       
[11,  5.3,  7.9,  4.7],
       
[12,  6.6,  8.4,  5.2],
       
[13,  4.8,  6.3,  3.6],
       
[14,  4.2,  6.2,  3.4]
     
]);
Full example here --- https://developers.google.com/chart/interactive/docs/gallery/linechart#top-x-charts

On Wed, Jun 6, 2018 at 10:01 PM, 'Daniel LaLiberte' via Google Visualization API <google-visua...@googlegroups.com> wrote:
I think the problem is that you are mixing table formats.  

"rows":[
["2018-05-06T11:15:00-0400",0.10,0.0,10,0.10,0.12],
  ...
That won't work because the structure is unexpected.  It would need to be more like:
rows: [
          {c: [{v: 'Baltimore Ravens'},     {v: 'Date(2000, 8, 5)'}, {v: 'Date(2001, 1, 5)'}]},
as documented here:


Note that each row is an object with 'c' property.

On Wed, Jun 6, 2018 at 9:53 PM Daniel LaLiberte <dlali...@google.com> wrote:
Leave the "new " off of the string and it should work better.

On Wed, Jun 6, 2018 at 8:22 PM Wes Melton <w...@smokymountains.com> wrote:
Hi Daniel,

Taking your suggestion, we've modified the output to send a string with a new Date constructor in to the Graph API, but now the error is saying: 

"Error: Type mismatch. Value Date(2018,05,06,11,15) does not match type datetime in column index 0"

Example array: 

["new Date(2018,05,06,11,15)", 0.1, 0.11, 0.09, 0.13, 0.13]

We tried it without the 'new' verb (e.g. "Date(2018,05,06,11,15)" and that didn't work either. 

Scratching our heads here a little bit.

On Wed, Jun 6, 2018 at 5:13 PM, 'Daniel LaLiberte' via Google Visualization API <google-visualization-api@googlegroups.com> wrote:
If you can pass a constructor to a place where JavaScript interprets it, then JavaScript will interpret it.  The "Date(...)" form is parsed by Google Charts, as if it were a constructor, even though it is a string.

On Wed, Jun 6, 2018 at 5:12 PM Wes Melton <w...@smokymountains.com> wrote:
Data is coming from a PHP server.

If a constructor is passed as a literal string in the output from the PHP server, you are saying the library will parse it?


From: 'Daniel LaLiberte' via Google Visualization API <google-visualization-api@googlegroups.com>
To unsubscribe from this group and stop receiving emails from it, send an email to google-visualization-api+unsub...@googlegroups.com.
To post to this group, send email to google-visualization-api@googlegroups.com.


--
dlaliberte@Google.com   5CC, Cambridge MA

--
You received this message because you are subscribed to the Google Groups "Google Visualization API" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-visualization-api+unsub...@googlegroups.com.
To post to this group, send email to google-visualization-api@googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "Google Visualization API" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-visualization-api+unsub...@googlegroups.com.
To post to this group, send email to google-visualization-api@googlegroups.com.


--

--
You received this message because you are subscribed to the Google Groups "Google Visualization API" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-visualization-api+unsub...@googlegroups.com.
To post to this group, send email to google-visualization-api@googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "Google Visualization API" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-visualization-api+unsub...@googlegroups.com.
To post to this group, send email to google-visualization-api@googlegroups.com.


--


--

--
You received this message because you are subscribed to the Google Groups "Google Visualization API" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-visualization-api+unsub...@googlegroups.com.
To post to this group, send email to google-visualization-api@googlegroups.com.

Wes Melton

unread,
Jun 7, 2018, 2:25:05 PM6/7/18
to Google Visualization API
I was able to make this work by parsing it manually from the string in JS and creating a Date object properly. 

Still seems super buggy to pass in an ISO8601 datetime string that's syntactically correct, and the library to respond that it's not of the correct format. 

Ponni Mano

unread,
Jun 7, 2018, 2:34:47 PM6/7/18
to Google Visualization API
It doesn't a datetime format. So either you declare as a string

Daniel LaLiberte

unread,
Jun 7, 2018, 2:35:59 PM6/7/18
to Google Visualization API
Be aware that each browser could interpret your datetime string differently.  See:


That's the main reason we haven't supported any other datetime string format so far, but it is conceivable that we could in the future.


From: 'Daniel LaLiberte' via Google Visualization API <google-visua...@googlegroups.com>
To unsubscribe from this group and stop receiving emails from it, send an email to google-visualizati...@googlegroups.com.
To post to this group, send email to google-visua...@googlegroups.com.


--
dlaliberte@Google.com   5CC, Cambridge MA

--
You received this message because you are subscribed to the Google Groups "Google Visualization API" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-visualizati...@googlegroups.com.
To post to this group, send email to google-visua...@googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "Google Visualization API" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-visualizati...@googlegroups.com.
To post to this group, send email to google-visua...@googlegroups.com.


--

--
You received this message because you are subscribed to the Google Groups "Google Visualization API" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-visualizati...@googlegroups.com.
To post to this group, send email to google-visua...@googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "Google Visualization API" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-visualizati...@googlegroups.com.
To post to this group, send email to google-visua...@googlegroups.com.


--


--

--
You received this message because you are subscribed to the Google Groups "Google Visualization API" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-visualizati...@googlegroups.com.
To post to this group, send email to google-visua...@googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "Google Visualization API" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-visualizati...@googlegroups.com.
To post to this group, send email to google-visua...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

Ponni Mano

unread,
Jun 7, 2018, 2:36:35 PM6/7/18
to Google Visualization API
Dynamically from table you will write as a datetime format. Like convert(datetime,@string).
Reply all
Reply to author
Forward
0 new messages