I'm trying to make a div element in JavaScript and place a google chart on it.
google.setOnLoadCallback(drawChart)
function drawChart() {
div = document.createElement('div');
div.id = 1;
div.style.position = 'absolute';
div.style.top = 291;
div.style.left = 439;
div.style.width = 500;
div.style.height = 500;
document.body.appendChild(div);
var data = google.visualization.arrayToDataTable([
['Task', 'Hours per Day'],
['Work', 1],
['Eat', 2],
['Commute', 2],
['Watch TV', 2],
['Sleep', 2]
]);
var options = {'title':'How Much Pizza I Ate Last Night',
'width':300,
'height':300};
var pieChart = new google.visualization.PieChart(document.getElementById(1));
pieChart.draw(data, options);
}
Nothing shows up... but if I manually make a div in body with <div> tag... and give its id here, that works. Am I doing something wrong with new div creation or what?
google.setOnLoadCallback(drawChart)not be after the function being defined? ie in the end of that script?