Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>In order to get this to work you need to:</p> <ol> <li>use the <code>onComplete</code> option of the fancybox call</li> <li>explicitly specify a width and height style attribute for the div in which the chart will be drawn</li> </ol> <p>It's common enough with gviz for the div to be visible/drawn before trying to put a chart in it, else you can end up with some pretty odd looking charts (not sure what goes on when you try to render a chart in an invisible div..). The onComplete takes care of this. Using the gviz image library is a good workaround for that problem in other cases.</p> <p>Anyway, here's a working example of using fancybox and gviz (pie chart code taken from <a href="http://code.google.com/apis/ajax/playground/#pie_chart" rel="nofollow">google code playground</a>):</p> <pre><code> &lt;html xmlns="http://www.w3.org/1999/xhtml"&gt; &lt;head&gt; &lt;script type="text/javascript" src="http://www.google.com/jsapi"&gt;&lt;/script&gt; &lt;script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4/jquery.min.js"&gt;&lt;/script&gt; &lt;script type="text/javascript" src="http://fancybox.net/js/fancybox-1.3.4/jquery.fancybox-1.3.4.js"&gt;&lt;/script&gt; &lt;link rel="stylesheet" href="http://fancybox.net/js/fancybox-1.3.4/jquery.fancybox-1.3.4.css" type="text/css" media="screen" /&gt; &lt;script type="text/javascript"&gt; google.load('visualization', '1', {packages: ['piechart']}); &lt;/script&gt; &lt;script type="text/javascript"&gt; &lt;/script&gt; &lt;script&gt; function drawVisualization() { var data = new google.visualization.DataTable(); data.addColumn('string', 'Task'); data.addColumn('number', 'Hours per Day'); data.addRows(5); data.setValue(0, 0, 'Work'); data.setValue(0, 1, 11); data.setValue(1, 0, 'Eat'); data.setValue(1, 1, 2); data.setValue(2, 0, 'Commute'); data.setValue(2, 1, 2); data.setValue(3, 0, 'Watch TV'); data.setValue(3, 1, 2); data.setValue(4, 0, 'Sleep'); data.setValue(4, 1, 7); // Create and draw the visualization. new google.visualization.PieChart(document.getElementById('data')).draw(data); } $(document).ready(function() { $("a#inline").fancybox({ 'hideOnContentClick': true, onComplete: drawVisualization }); }); &lt;/script&gt; &lt;/head&gt; &lt;body&gt; &lt;a id="inline" href="#data"&gt;Click here to see chart&lt;/a&gt; &lt;div style="display:none"&gt;&lt;div style='height:200px;width:200px' id="data"&gt;&lt;/div&gt;&lt;/div&gt; &lt;/body&gt; &lt;/html&gt; </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload