How to embed Interactive Google Charts into Confluence Page using html macro Edited

I have successfully loaded a static chart from Google Charts using the html Macro. However, when I try to load an interactive chart, it shows when i click 'preview' but when i save the changes the whole page just comes up blank. any ideas how to fix this?  The code I have tried to use is below.

{html}  
	<head>     
		<script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script>     
		<script type="text/javascript">       
		google.charts.load('current', {'packages':['corechart', 'controls']});       
		google.charts.setOnLoadCallback(drawStuff);
      
		function drawStuff() {
        
			var dashboard = new google.visualization.Dashboard(           
			document.getElementById('programmatic_dashboard_div'));
        		// We omit "var" so that programmaticSlider is visible to changeRange.         
			var programmaticSlider = new google.visualization.ControlWrapper({           
			'controlType': 'NumberRangeFilter',           
			'containerId': 'programmatic_control_div',           
			'options': {             
				'filterColumnLabel': 'Donuts eaten',             
				'ui': {'labelStacking': 'vertical'}           }         });
        		var programmaticChart  = new google.visualization.ChartWrapper({           
			'chartType': 'PieChart',           
			'containerId': 'programmatic_chart_div',           
			'options': {             
				'width': 300,             
				'height': 300,             
				'legend': 'none',             
				'chartArea': {'left': 15, 'top': 15, 'right': 0, 'bottom': 0},             
				'pieSliceText': 'value'           }         });
        		var data = google.visualization.arrayToDataTable([           
			['Name', 'Donuts eaten'],           
			['Michael' , 5],           
			['Elisa', 7],           
			['Robert', 3],           
			['John', 2],           
			['Jessica', 6],           
			['Aaron', 1],           
			['Margareth', 8]         ]);
        		dashboard.bind(programmaticSlider, programmaticChart);         
			dashboard.draw(data);
        		changeRange = function() {           
				programmaticSlider.setState({'lowValue': 2, 'highValue': 5});          
				programmaticSlider.draw();         };
        		changeOptions = function() {           
				programmaticChart.setOption('is3D', true);           
				programmaticChart.draw();         };       }
 
    		</script>   
	</head>   
	<body>     
		<div id="programmatic_dashboard_div" style="border: 1px solid #ccc">       
			<table class="columns">         
				<tr>           
					<td>             
						<div id="programmatic_control_div" style="padding-left: 2em; min-width: 250px"></div>             
						<div>               
							<button style="margin: 1em 1em 1em 2em" onclick="changeRange();">                 
							Select range [2, 5]               
							</button><br />               
							<button style="margin: 1em 1em 1em 2em" onclick="changeOptions();">                 
							Make the pie chart 3D               
							</button>             
						</div>             
						<script type="text/javascript">               
							function changeRange() {                 
							programmaticSlider.setState({'lowValue': 2, 'highValue': 5});                 
							programmaticSlider.draw();               }
              						function changeOptions() {                 
							programmaticChart.setOption('is3D', true);                 
							programmaticChart.draw();               }             
 
						</script>           
					</td>           
					<td>             
						<div id="programmatic_chart_div"></div>           
					</td>         
				</tr>       
			</table>     
		</div>   
	</body> 
{html}

 

1 answer

This widget could not be displayed.

Hello Kelly,

You may have better luck creating a user macro for this. There's some information on another community question with the basics to do this. Unfortunately our API has changed since then, so you may need to make some tweaks there.

Let us know if you have any questions about this!

Kind Regards,
Shannon

Suggest an answer

Log in or Sign up to answer
Atlassian Summit 2018

Meet the community IRL

Atlassian Summit is an excellent opportunity for in-person support, training, and networking.

Learn more
Community showcase
Published Jul 30, 2018 in Confluence

How Manon Soubies-Camy uses Confluence + Trello to organize webinar notes and her knitting stash

@Manon Soubies-Camy is an engineer who has been an avid Atlassian user since 2014. She helps companies of all sizes transform the way they work with the Atlassian stack, including Jira and Confl...

863 views 8 13
Read article

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you