javascript - Uncaught Error: Container is not defined
Get the solution ↓↓↓Solution:
You are missing : " on the div style
<div id="chart_div" style="width: 900px; height: 200px;></div>
Thediv
is not defined, so the JS cant find it.
ThegetElementById
failed.
Answer
Solution:
I think you are havingdata
format issue, try this
/*
// assuming you are having data object in this format, with columns (first : string, second: integer)
data = [
['Mushrooms', 3],
['Onions', 1],
['Olives', 1],
['Zucchini', 1],
['Pepperoni', 2]
]
*/
// 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);
function get_gchart_data(data) {
var g_data = new google.visualization.DataTable();
g_data.addColumn('string', 'Topping');
g_data.addColumn('number', 'Slices');
g_data.addRows(data);
return g_data;
}
function drawChart() {
$.ajax({
url: "localhost:8080/index1.php",
dataType:"json",
async: false ,
success: function(data) {
var g_data = get_gchart_data(data);
// Instantiate and draw our chart, passing in some options.
var chart = new google.visualization.Timeline(document.getElementById('chart_div'));
chart.draw(g_data, {width: 500, height: 240});
}
})
};
Answer
Solution:
Try this, I think you are accessingjsonData
on wrong place.
<script type="text/javascript">
$(function() {
// 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);
function drawChart() {
$.ajax({
url: "localhost:8080/index1.php",
dataType:"json",
async: false ,
success: function(data) {
jsonData = data;
// Create our data table out of JSON data loaded from server.
var data = new google.visualization.DataTable(jsonData);
// Instantiate and draw our chart, passing in some options.
var chart = new google.visualization.Timeline(document.getElementById('chart_div'));
chart.draw(data, {width: 500, height: 240});
}
})
};
});
</script>
Share solution ↓
Additional Information:
Link To Answer People are also looking for solutions of the problem: can't write image data to path
Didn't find the answer?
Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.
Similar questions
Find the answer in similar questions on our website.
Write quick answer
Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.