Google charts Tooltip with click event

2,730 views
Skip to first unread message

Naresh Maruthi Jayaraman

unread,
May 3, 2016, 3:28:48 PM5/3/16
to Google Visualization API
Hi all,

I am having a google chart with tooltip on hover over charts. I am trying to have a export button in the tooltip which just exports the current selection of the whole chart.

How should i trigger an event when user clicks on export link in the tooltip?

Note: I want to capture the event only if the user clicks that button in the tooltip not when the user selects the barchart!

I have this in options and chart.setAction. Also i couldnt do action in setAction and isHTML: true together. Thoughts on that would also be helpful.

tooltip: {
              isHtml: true,
              trigger: 'both'
        }, 

chart.setAction({
        id: 'sample',
        text: 'Export data',
        enabled: function() {
        var selection = chart.getSelection();
          //     some code 
         }

Thanks!!

Zhenhui Piao

unread,
May 19, 2017, 3:45:08 PM5/19/17
to Google Visualization API
You can try add this code.

var clicktip='<div id="fonttest"> <a href="test2.html" onclick="info()">hellow</a> </div>';
        var data = google.visualization.arrayToDataTable([
          ['Genre', 'Percentage of my books',{role: 'tooltip', type: 'string', p: {html:true,trigger:'selection'}}],
          ['Science Fiction', 217,clicktip],
          ['General Science', 203,clicktip],
          ['Computer Science', 175,clicktip]
        ]);
var options = { tooltip: { isHtml:true,trigger: 'selection'}};
chart.setAction({
            id: 'id',
            text: 'click',
            action: function() {
              alert('success');
            }
        });
chart.draw(data, options);

If you are working on Piechart it works, but I tried on Timeline it failed to read setAction() function.
Reply all
Reply to author
Forward
0 new messages