getRowProperties - how to use this

968 views
Skip to first unread message

NA

unread,
Nov 14, 2011, 11:52:47 AM11/14/11
to Google Visualization API
I'm having some trouble with getRowProperties. I have:

function drawVisualization() {
var dataTable = new google.visualization.DataTable();
dataTable.addColumn('string', 'Name');
dataTable.addColumn('number', 'Age');
dataTable.addColumn('string', 'Instrument');
dataTable.addColumn('string', 'Color');
dataTable.addRows(1);
dataTable.setCell(0, 0, 'John');
dataTable.setCell(0, 1, 24);
dataTable.setCell(0, 2, 'Guitar');
dataTable.setCell(0, 3, 'Blue');

alert(dataTable.getRowProperties(0)['Name']);
}

I'm expecting to see the string "John". Instead, I get "undefined".

What is the return of getRowProperties? The doc indicates that it's a
map, which I assumed is also an Object, but it doesn't seem to be one
from my tests.

Can someone show me how to use getRowProperties?

asgallant

unread,
Nov 14, 2011, 12:42:43 PM11/14/11
to google-visua...@googlegroups.com
What you want is DataTable#getValue(rowIndex, columnIndex) method, so to get the value in the first row of the 'Name' column, you would use dataTable.getValue(0, 0);

MC Get Vizzy

unread,
Nov 14, 2011, 12:46:37 PM11/14/11
to google-visua...@googlegroups.com
Note that the chart tools API does not support accessing columns by label (or id), but only by index.

On Mon, Nov 14, 2011 at 7:42 PM, asgallant <drew_g...@abtassoc.com> wrote:
What you want is DataTable#getValue(rowIndex, columnIndex) method, so to get the value in the first row of the 'Name' column, you would use dataTable.getValue(0, 0);

--
You received this message because you are subscribed to the Google Groups "Google Visualization API" group.
To view this discussion on the web visit https://groups.google.com/d/msg/google-visualization-api/-/IX-J7gUU2yUJ.

To post to this group, send email to google-visua...@googlegroups.com.
To unsubscribe from this group, send email to google-visualizati...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/google-visualization-api?hl=en.

NA

unread,
Nov 14, 2011, 2:04:39 PM11/14/11
to Google Visualization API
I'm not understanding asgallant's or MC Get Vizzy's comments. In
fact, it seems like you're talking about getValue() but I'm talking
about getRowProperties().

There's a method called getRowProperties documented here:

http://code.google.com/apis/chart/interactive/docs/reference.html#DataTable_getRowProperties

The signature is getRowProperties(rowIndex). The output of this
method is an object. But when I tried to use this method, I didn't
get the response I expected to see.

Can someone show me how to use that method?

asgallant

unread,
Nov 14, 2011, 2:38:08 PM11/14/11
to google-visua...@googlegroups.com
It probably returning an empty object because you didn't set any properties for that row.

MC Get Vizzy

unread,
Nov 14, 2011, 2:45:57 PM11/14/11
to google-visua...@googlegroups.com
dataTable.setRowProperties(0, {'hello': 'world'});
var rowProperties = dataTable.getRowProperties(0);

The getRowProperties() method does not return the data in the cells.  It only returns whatever you passed in when you called setRowProperties().

The DataTable class allows the user to set "custom properties" on elements of the table: columns, rows, cells, and the table itself.  This allows an application to dynamically extend the DataTable API and attach arbitrary data structures to a DataTable.  It might be useful for servers that want to "annotate" the DataTable with extra information that doesn't fit neatly into columns and rows.

--
You received this message because you are subscribed to the Google Groups "Google Visualization API" group.

NA

unread,
Nov 14, 2011, 3:36:23 PM11/14/11
to Google Visualization API
That explains it - I thought this was a way to get back the data in
the row.

Is there a method that returns the data in a row (including value,
type, format, etc)? Or do I need to write my own?

asgallant

unread,
Nov 14, 2011, 3:43:23 PM11/14/11
to google-visua...@googlegroups.com
DataTable#getValue(rowIndex, columnIndex) returns the value
DataTable#getFormattedValue(rowIndex, columnIndex) returns the string-formatted value (either as determined by the API or as set by the user)
DataTable#getColumnType(columnIndex) returns the data type of the column (string, number, date, etc)

NA

unread,
Nov 14, 2011, 3:58:58 PM11/14/11
to Google Visualization API
So it sounds like there isn't a method, I'll just have to roll one
myself out of the other get* methods, including the ones asgallant.

I'm going to create an enhancement request for this, as I think it's
useful to be able to extract a row from a table for later
manipulations.

In fact, it's also useful to extract a row from one table and insert
it into another table. There is an "addRow" method, but unfortunately
the removeRow(s) and hideRow(s) methods don't produce a return value.
These deletion operators often produce return values showing what they
removed. If the gviz library did that, this output value could be
used later with addRow in a very elegant manner.

thanks for the suggestions,

Reply all
Reply to author
Forward
0 new messages