Formatter html appears in tooltips

76 views
Skip to first unread message

NA

unread,
Jun 9, 2011, 10:35:53 AM6/9/11
to Google Visualization API
If you apply a formatter to a datatable, such as BarFormat, and then
use that datatable as the source for a chart or graph, the tooltips
display the html markup created by the formatter.

Is there a way to prevent this?

My workaround now is to clone the datatable before applying the
BarFormat, but this is probably wasteful of memory.

Incidentally, is there any reason that the formatters are applied to
the underlying data source instead of to data view objects?

asgallant

unread,
Jun 9, 2011, 11:35:54 AM6/9/11
to google-visua...@googlegroups.com
I believe you need to set the option "allowHtml" to true.

NA

unread,
Jun 9, 2011, 3:38:20 PM6/9/11
to Google Visualization API
Is there an allowHtml option for the charts or for the tooltips? I
know this option exists for the datatables, but I didn't think it
existed for the charts or tooltips and that's what is causing the
problem.

Can you confirm that you are able to set allowHtml for a chart or
tooltip?

asgallant

unread,
Jun 10, 2011, 9:08:11 AM6/10/11
to google-visua...@googlegroups.com
allowHTML is a chart option, not a dataTable option.

NA

unread,
Jun 10, 2011, 9:32:51 AM6/10/11
to Google Visualization API
You are misunderstanding the problem. Run the code snippet below.
The html formatting applied to the datatable appears in the tooltips
for the PieChart. The PieChart does not have an allowHtml option
(it's not documented, and I tried it anyway and it didn't work). This
is a problem.

In my case, I am visualizing the data both in a Table and in a
PieChart. I want to use formatting in the Table, but then the html
code appears in the PieChart's tooltips. To work around this, I need
to clone the table before formatting it, which wastes memory.

Can you please take a closer look at this? This seems like a bug to
me. In fact, the whole idea of applying the formatter to the
datatable and not to the dataview doesn't make sense to me.

In any case, please run the snippet below and let me know what you
think.


function drawVisualization() {
// Create and populate the data table.
var data = new google.visualization.DataTable();
data.addColumn('string', 'Task');
data.addColumn('number', 'Hours per Day');
data.addRows(5);
data.setValue(0, 0, 'Work');
data.setValue(0, 1, 11);
data.setValue(1, 0, 'Eat');
data.setValue(1, 1, 2);
data.setValue(2, 0, 'Commute');
data.setValue(2, 1, 2);
data.setValue(3, 0, 'Watch TV');
data.setValue(3, 1, 2);
data.setValue(4, 0, 'Sleep');
data.setValue(4, 1, 7);

var formatter = new google.visualization.TableBarFormat({width:
120});
formatter.format(data, 1); // Apply formatter to second column

// Create and draw the visualization.
new
google.visualization.PieChart(document.getElementById('visualization')).
draw(data, {title:"So, how was your day?"});

asgallant

unread,
Jun 10, 2011, 11:12:01 AM6/10/11
to google-visua...@googlegroups.com
Oh, I see your problem now.  If it isn't already implemented or in planning, this should be addressed by the new chart dashboards.

In the meantime, I see two potential ways to get around the problem, depending on how you need to use the charts:

1) If you need to draw the charts only once for a given set of data, draw the pie chart first, then apply the formatter and draw the table.

2) You can create your data table with the column to format in it twice.  Apply the formatter to one of the instances of that column, then create two data views: one which excludes the formatted column and one which excludes the unformatted column.  Draw your pie chart with the first view and the table with the second.

The second method uses more memory than the first, but less than duplicating the entire dataTable object.

NA

unread,
Jun 10, 2011, 11:54:32 AM6/10/11
to Google Visualization API
Ah, nice suggestions! The second idea is pretty clever, that will
work best for me. Thanks.

Regarding the dashboards - I was under the impression that the
dashboard stuff is still new and may be a little buggy. I chose to
build my dashboard app using the regular visualization API, and
planned to reimplement it with the dashboard API later, once they were
more mature. Is my perception correct, or are the dashboard tools as
mature as the regular visualizaton APIs ?

thanks again for the suggestions,

asgallant

unread,
Jun 10, 2011, 12:46:46 PM6/10/11
to google-visua...@googlegroups.com
AFAIK, the dashboards are still very much in flux, so you can't depend on them for anything beyond testing at this point.  My comment was more directed towards the developers as a hint that it should be on the feature list if it isn't already.

Jinji

unread,
Jun 12, 2011, 9:53:47 AM6/12/11
to google-visua...@googlegroups.com
BTW, please don't confuse the DataTable and the Table Visualization. DataTable is a data structure that holds tabular data and have no UI. It's used to pass data into all visualizations that are part of the Google Visualization API, including the Table Visualization. The Table Visualization is a UI element.


On Fri, Jun 10, 2011 at 7:46 PM, asgallant <drew_g...@abtassoc.com> wrote:
AFAIK, the dashboards are still very much in flux, so you can't depend on them for anything beyond testing at this point.  My comment was more directed towards the developers as a hint that it should be on the feature list if it isn't already.

--
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/-/dzUEimsfDKoJ.

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.

Reply all
Reply to author
Forward
0 new messages