Align right in DataTable columns for STRING

3,104 views
Skip to first unread message

Luis

unread,
Aug 19, 2010, 6:48:59 PM8/19/10
to Google Visualization API
Hi all,

I'm trying to add text to a set of columns in a DataTable, but for
certain columns I want to align the text to the right. I've notice
that by default for columns of type STRING the content is left
aligned, and for type NUMBER the content is right aligned.

DataTable data = DataTable.create();
data.addColumn(ColumnType.STRING, "This should be left aligned");
data.addColumn(ColumnType.STRING, "This should be right aligned");

data.addRows(X);

data.setValue(0, 0,"Value A - On the left");
data.setValue(0, 1,"Value B - On the right");

Does anyone how to make this work the way I need?

Many thanks in advanced,
Luis

Luis

unread,
Aug 20, 2010, 11:23:14 AM8/20/10
to Google Visualization API
Well I think I got it. You just need to add:

Properties properties = Properties.create();
properties.set("style", "text-align: right");

data.setProperties(0, 0, properties);
data.setProperties(0, 0, properties);

Regards,
Luis

asgallant

unread,
Sep 4, 2012, 12:58:51 PM9/4/12
to google-visua...@googlegroups.com
You set properties on DataTable cells.  Table Visualizations accept CSS style information as properties, so you need to set the "style" property of each cell you want to style.  Use something like this:

data.setProperties(<rowIndex><columnIndex>{style'text-align: right; color: red'}); 

where the rowIndex and columnIndex are the indices of the row and column that identify the cell.  The style string can be any valid CSS.

On Tuesday, September 4, 2012 9:51:01 AM UTC-4, ismail atkurt wrote:
Hi Luis,

I am dealing with the same problem but I couldn't apply your solution.
can you explain it briefly..

best regards

20 Ağustos 2010 Cuma 01:48:59 UTC+3 tarihinde Luis yazdı:

asgallant

unread,
Sep 4, 2012, 12:59:36 PM9/4/12
to google-visua...@googlegroups.com
Oh, and I forgot to mention: to make this work you must set the "allowHtml" option to true when you draw the Table.
Reply all
Reply to author
Forward
0 new messages