format DataTable cell on string pattern match

173 views
Skip to first unread message

ficuscr

unread,
Jul 10, 2011, 10:42:23 PM7/10/11
to Google Visualization API
A noob question here. Trying to figure out how I can set a class, or
otherwise style a cell in a DataTable, based off a string pattern in a
given cell. I see the google.visualization.ColorFormat class but it
only works with a number range. Is there not a method to format using
regex pattern matches? Should I be passing this with the underlying
data instead? Looking for advice. Hope this is the appropriate
place to ask. Thanks.

MC Get Vizzy

unread,
Jul 11, 2011, 6:38:52 AM7/11/11
to google-visua...@googlegroups.com
I don't think there's any class that does this, but you should be able to loop over the data table and call setFormattedValue() on each cell.


--
You received this message because you are subscribed to the Google Groups "Google Visualization API" group.
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.


ficuscr

unread,
Jul 11, 2011, 12:58:50 PM7/11/11
to google-visua...@googlegroups.com
Ok, after reading more I see a method which works fine for what I needed.  Using the PatternFormat I can use the distinct string values as class names to set a style on the 'cell'.

var formatter = new google.visualization.PatternFormat('<div class="class{0}">{0}</div>');
formatter.format(dataTable, [2]);

Works for this simple case.  Would still be nice if there were something that combined the functionality of ColorFormat with regular expressions or a some other more advanced logic than just numeric ranges.
Reply all
Reply to author
Forward
0 new messages