A better way to update data

76 views
Skip to first unread message

API Developer

unread,
Aug 14, 2012, 10:06:01 AM8/14/12
to google-visua...@googlegroups.com
Hey guys,

Does anybody know a good way to insert rows into the dataTable?
Would it be better to just add directly to the data using data.addRows() or use a separate matrix and use google.visualization.arrayToDataTable?

Yolanda Davis

unread,
Aug 14, 2012, 10:14:23 AM8/14/12
to google-visua...@googlegroups.com
I think it depends on what you are doing.  If you need to add more specific column information (such as column id and column type) or need to use Date/Datetime as a type it may be better to use the addColumn and addRow methods vs the arrayToDataTable. The arrayToDataTable will interpret the types based on content, except it cannot detect the Date type nor can it read Javascript literals in the data. See  https://developers.google.com/chart/interactive/docs/reference#google.visualization.arraytodatatable  for more info.

asgallant

unread,
Aug 14, 2012, 12:16:34 PM8/14/12
to google-visua...@googlegroups.com
Also, with arrayToDataTable, you have to replicate the entire DataTable - you can't add new data to an existing DataTable that way.

If you are creating a DataTable from scratch, performance-wise, the fastest method is actually to pass a JSON representation of the DataTable to the DataTable constructor (see here).  Manually defining columns and then using the #addRows method is probably marginally faster than arrayToDataTable, as the API doesn't have to determine the column data types.

API Developer

unread,
Aug 14, 2012, 9:06:25 PM8/14/12
to google-visua...@googlegroups.com
Thanks guys!
Reply all
Reply to author
Forward
0 new messages