Hi all!
I have got an html which contains a google chart. When I run this html
on its own everything is fine. My next step is to load this .html when
I click a button in another file, so it is loaded in the new page
dynamically. But when i hit the button nothing shows up and the
browser is trying to load something from
google.com without getting
somewhere
Below theres the code of the two simple files that are needed to
reproduce this error:
gchart.htm
-------------------------------------------------------------------------------------------------------
<html>
<head>
<title>Test chart</title>
<script src="
http://code.jquery.com/jquery-latest.js"></script>
<script type="text/javascript" src="
https://www.google.com/
jsapi"></script>
<script type="text/javascript">
// Load the Visualization API and the piechart package.
google.load('visualization', '1', {'packages':['corechart']});
// Set a callback to run when the Google Visualization API is
loaded.
google.setOnLoadCallback(drawChart);
// Callback that creates and populates a data table,
// instantiates the pie chart, passes in the data and
// draws it.
function drawChart() {
// Create our data table.
var data = new google.visualization.DataTable();
data.addColumn('string', 'Topping');
data.addColumn('number', 'Slices');
data.addRows([
['Wiesen', 2],
['Acker', 3],
['versiegelt', 6],
['versiegelt', 6]
]);
// Instantiate and draw our chart, passing in some
options.
var chart = new
google.visualization.PieChart(document.getElementById('gchart'));
chart.draw(data, {width: 300, height: 200, colors:
['#006400','#CD853F','#C0C0C0','#228B22','#556B2F','#1E90FF','#000000'],
legend: 'right', chartArea:{width:"90%", height:"85%"},
backgroundColor: 'white', pieSliceText:"none"});
}
</script>
</head>
<body>
<div id="gchart"></div>
</body>
</html>
-------------------------------------------------------------------------------------------------------
and gchart_test.htm - the file that calls the .html containing the
chart
-------------------------------------------------------------------------------------------------------
<html>
<head>
<script src="
http://code.jquery.com/jquery-latest.js"></script>
<script type="text/javascript" src="
https://www.google.com/
jsapi"></script>
</head>
<body>
<input type="button" id="gshow" value="Test Gchart">
<div id="gchart"></div>
<script type="text/javascript">
// load() functions
var loadUrl = "gchart.htm";
$("#gshow").click(function(){
$("#gchart").load(loadUrl);
});
</script>
</body>
</html>
-------------------------------------------------------------------------------------------------------
Has anybody got a clue what is going wrong?
Thank you very much for your help!