Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Add HTML Link to Google Charts Table

Tags:

javascript

I'm trying to add an HTML link to a Google Chart Table column. I have setHTML: true for both the column and the table, but its just showing the HTML code instead of interpreting it. Can someone point me in the right direction?

Thanks

<!--
You are free to copy and use this sample in accordance with the terms of the
Apache license (http://www.apache.org/licenses/LICENSE-2.0.html)
-->

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <meta http-equiv="content-type" content="text/html; charset=utf-8"/>
    <title>
      Google Visualization API Sample
    </title>
    <script type="text/javascript" src="http://www.google.com/jsapi"></script>
    <script type="text/javascript">
      google.load('visualization', '1', {packages: ['table']});
    </script>
    <script type="text/javascript">

     function drawVisualization() {
      // Create and populate the data table.
      var data = google.visualization.arrayToDataTable([
        ['Name', 'Logged In'],

        ['<a href="LINK">Item 1</a>', 'Item 2'],
     ]);

       data.setColumnProperty(0, {allowHTML: true});
   // Create and draw the visualization.
   visualization = new google.visualization.Table(document.getElementById('table'));
       visualization.draw(data, {allowHTML: true});
    }

   google.setOnLoadCallback(drawVisualization);
    </script>
  </head>
  <body style="font-family: Arial;border: 0 none;">
    <div id="table"></div>
  </body>
</html>
​
like image 263
Michael Shnitzer Avatar asked Jan 15 '13 17:01

Michael Shnitzer


People also ask

Can I use Google charts on my website?

Google Charts provides a perfect way to visualize data on your website. From simple line charts to complex hierarchical tree maps, the chart gallery provides a large number of ready-to-use chart types. The most common way to use Google Charts is with simple JavaScript that you embed in your web page.

How do I add data to a Google chart?

Double-click the chart you want to change. At the right, click Setup. Select the cells you want to include in your chart. Optional: To add more data to the chart, click Add another range.


1 Answers

The allowHTML property is case sensitive. It has to be {allowHtml: true}.

like image 162
Michael Shnitzer Avatar answered Sep 19 '22 14:09

Michael Shnitzer