Search code examples
htmlgoogle-visualizationtooltiporgchart

Google Chart with HTML tool tip


I am trying to add an html tooltip tp my google chart but that does not work. I have defined the column and option to enable HTML but that does not work

Here is the jsfiddle which does not work. The js is defined as

  google.setOnLoadCallback(drawChart);
  function drawChart() {
    var data = new google.visualization.DataTable();
    data.addColumn('string', 'Name');
    data.addColumn('string', 'Manager');
    data.addColumn({'type': 'string', 'role': 'tooltip', 'p': {'html': true}});


    data.addRows([
      [{v:'Mike', f:'Mike<div style="color:red; font-style:italic">President</div>'}, '', 'The President'],
        [{v:'Jim', f:'Jim<div style="color:red; font-style:italic">Vice President<div>'}, 'Mike', '<div style="color:red; font-style:italic">Vice President<div>'],
      ['Alice', 'Mike', ''],
      ['Bob', 'Jim', '<b>Bob</b> Sponge'],
      ['Carol', 'Bob', '']
    ]);

    var chart = new google.visualization.OrgChart(document.getElementById('chart_div'));
    var  options = {
        tooltip: {isHtml: true},
          allowHtml:true
    };
    chart.draw(data, options);
  }

..and the HHTML

<script type="text/javascript" src="https://www.google.com/jsapi?autoload={'modules':[{'name':'visualization','version':'1','packages':['orgchart']}]}"></script>
   <div id="chart_div""></div>

Any help on this is greatly appreciated


Solution

  • Unfortunately org chart does not support custom tooltips. In fact, it does not suppport tooltips at all, the text on hover is just the title attribute. However, there are a few libraries that allow html titles. One example is jquery ui, with an addition of this code for it to work:

      $(function () {
          $(document).tooltip({
              content: function () {
                  return $(this).prop('title');
              }
          });
      });
    

    Here is working fiddle: http://jsfiddle.net/juvian/vucp11qk/2/