So my situation is following:
I have a page that creates a google chart where I place the graph in div as an example in here https://google-developers.appspot.com/chart/interactive/docs/gallery/linechart
That works fine if I get that page to the other page by using iframe as
<iframe id="mychart" name="mychart" src="stuff/chart.html"
frameborder="0" onLoad=autoResize("mychart");></iframe>
but I would like to get it by using ajax.
I've tried following
<script type="text/javascript">
google.load('visualization', '1', {'packages':['corechart']});
</script>
<script type="text/javascript">
$(document).ready(function() {
google.setOnLoadCallback(function() {
$.ajax({type: 'get', format: 'html', timeout: 9000, url: 'stuff/chart.html', success:
function (data) {
console.log(data);
$('#mychart').html(data);
var result = $(data).filter('#chart_div');
console.log(result.html());
$('#mychart').html(result.html());
}});
});
});
</script>
Where the first log shows the html code as wanted but when logging the actual div that would contain the google chart I would like to show the result variable seems to be empty.
Here's outlined chart.html. I did take a lot of unrelated code off but you should get the idea.
<html>
<head>
<script type="text/javascript">
//Load the AJAX API
// Load the Visualization API
function drawChart() {
// Took out a lot of stuff
var data = new google.visualization.DataTable(jsonData);
var chart = new google.visualization.AreaChart(document.getElementById('chart_div'));
chart.draw(data, {
// Setting up parameters
});
}
// Set a callback to run when the Google Visualization API is loaded.
google.setOnLoadCallback(drawChart);
</script>
</head>
<body>
<!--Div that will hold a chart-->
<div id="chart_div"></div>
</body>
</html>
I did check google.setOnLoadCallback with jQuery $(document).ready(), is it OK to mix?
and a few other topics.
So is there a way to load the google chart in this way or should I just use iframe ? Since I guess what happens that other chart never got created or something ?
Thanks in advance!