I need to add in another row of text on each of the tooltips I'm displaying (on an area chart). I've included a screenshot to illustrate what I'm hoping to do.
My current chart: The chart with the additional text added. (This is what I'm trying to do):
I'm hoping to do this without having to use a third party JS for custom tooltips. Is there any way to just add another row of text-based content to be displayed in the default tooltips?
Any help is greatly appreciated.
Have a look at https://developers.google.com/chart/interactive/docs/roles#whatrolesavailable:
Additional tooltip rows are what you are looking for!
The example:
label: 'Year', 'Sales', null, 'Expenses', null role: domain, data, tooltip, data, tooltip '2004', 1000, '1M$ sales, 400, '$0.4M expenses in 2004' in 2004' '2005', 1170, '1.17M$ sales, 460, '$0.46M expenses in 2005' in 2005' '2006', 660, '.66$ sales, 1120, '$1.12M expenses in 2006' in 2006' '2007', 1030, '1.03M$ sales, 540, '$0.54M expenses in 2007' in 2007'
If you enable focusTarget: 'category'
in the options. Then the tooltip
column becomes a value
for the the tooltip of the current x
,y
dots (which gets rendered the way you want). So you can mimic the value
and add the additional text you want. Here is an example what I mean:-
google.setOnLoadCallback(drawChart);
function drawChart() {
var dataTable = new google.visualization.DataTable();
dataTable.addColumn('string', 'Year');
dataTable.addColumn('number', 'Sales');
// A column for custom tooltip content
dataTable.addColumn({type: 'string', role: 'tooltip'});
dataTable.addRows([
['2010', 600,'600: 15% growth'],
['2011', 1500, '1500: 50% growth'],
['2012', 800, '800: -40% growth'],
['2013', 1000, '1000: 25% growth']
]);
var options = { legend: 'none', focusTarget: 'category'};
var chart = new google.visualization.ColumnChart(document.getElementById('col_chart_custom_tooltip'));
chart.draw(dataTable, options);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With