Geochart tooltip display

845 views
Skip to first unread message

Wendy Bardsley

unread,
Apr 25, 2014, 5:23:03 PM4/25/14
to google-visua...@googlegroups.com
Hello,
I've created a map that has 3 columns of Data: Country, Sentence(string), Value.
I only want to use the value to draw the colors on the map, but would like to omit it from the tooltip and just display Country(name) and Sentence.
After adding the 2nd string, it omits the Country Name on the tooltip, bolds the sentence and puts the value on a newline with Value: 2 (for example, number is bolded).
How can I format the tooltip so it shows the country name bolded on the first line, sentence on the 2nd line (not bold), and omits the value for the tooltip, while using it to draw the map?
The value has no intrinsic meaning, it doesn't relate to a unit, just to degree of severity.
Thanks for any help, or pointing me to documentation about adding columns,
Wendy

Andrew Gallant

unread,
Apr 25, 2014, 6:00:55 PM4/25/14
to google-visua...@googlegroups.com
What you want to do is use the "Sentence" column as the formatted value of the "Value" column.  You can use a DataView to accomplish this:

// create a DataView based on the DataTable "data"
var view = new google.visualization.DataView(data);
view.setColumns([0, {
    type: 'number',
    calc: function (dt, row) {
        return {v: dt.getValue(row, 2), f: dt.getValue(row, 1)};
    }
}]);

then draw the chart using the DataView instead of the DataTable.

Wendy Bardsley

unread,
Apr 28, 2014, 12:27:46 PM4/28/14
to google-visua...@googlegroups.com
Hi Andrew, 
This works great, except the 2nd line of the tooltip (sentence) starts with a space-colon-space, and it's bolded. Also the legend is still showing the numbers. Can I get the legend to show the sentence instead? Can you point to some documentation about the tooltip formatting (Showing a colon is the most important thing I want to get rid of, or move to the row above)?
Thanks so much,
Wendy

Andrew Gallant

unread,
Apr 28, 2014, 3:53:08 PM4/28/14
to google-visua...@googlegroups.com
You cannot change the legend to show the "sentence".

After some experimentation, I found that there is undocumented support for changing the tooltip contents.  I expect that this will be changed in the future, as it doesn't behave the same way as custom tooltips in other charts, but for now this should work.  You need to rearrange your three columns in this order: "Country", "Value", "Sentence", and set the "role" property of the "Sentence" column to "tooltip".  If you are using the DataTable#addColumns method, it would be like this:

data.addColumn('string', 'Country');
data.addColumn('number', 'Value');
data.addColumn({type: 'string', label: 'Sentence', role: 'tooltip'});


or if using the arrayToDataTable method:

['Country', 'Value', {type: 'string', label: 'Sentence', role: 'tooltip'}]

Wendy Bardsley

unread,
Apr 28, 2014, 4:27:55 PM4/28/14
to google-visua...@googlegroups.com
Did you change anything else? I'm getting the error:

Formatted value ('f'), if specified, must be a string.

I tried both methods.
Thanks so much, 
Wendy
T



--
You received this message because you are subscribed to a topic in the Google Groups "Google Visualization API" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/google-visualization-api/97YlJy_F2AU/unsubscribe.
To unsubscribe from this group and all its topics, send an email to google-visualizati...@googlegroups.com.
To post to this group, send email to google-visua...@googlegroups.com.
Visit this group at http://groups.google.com/group/google-visualization-api.
For more options, visit https://groups.google.com/d/optout.

Andrew Gallant

unread,
Apr 28, 2014, 7:54:20 PM4/28/14
to google-visua...@googlegroups.com
You don't use the DataView when using this method.
Wendy
T



To unsubscribe from this group and all its topics, send an email to google-visualization-api+unsub...@googlegroups.com.

Wendy Bardsley

unread,
Apr 28, 2014, 9:17:34 PM4/28/14
to google-visua...@googlegroups.com
Ah, Perfect! Thanks,
Wendy


To unsubscribe from this group and all its topics, send an email to google-visualizati...@googlegroups.com.

Muhammad Ali

unread,
May 2, 2014, 12:34:44 PM5/2/14
to google-visua...@googlegroups.com
つ ◕_◕ ༽つ GIB CODE つ ◕_◕ ༽つ
Reply all
Reply to author
Forward
0 new messages