Javascript 未捕获错误:未定义容器
我正在尝试使用Google图表生成甘特图,在使用现有php代码进行相应编码后,我得到一个空白html。请帮助我成功显示图表。Javascript 未捕获错误:未定义容器,javascript,php,charts,Javascript,Php,Charts,我正在尝试使用Google图表生成甘特图,在使用现有php代码进行相应编码后,我得到一个空白html。请帮助我成功显示图表。 <html> <head> <!--Load the AJAX API--> <script type="text/javascript" src="https://www.google.com/jsapi"></script> <script type="text/java
<html>
<head>
<!--Load the AJAX API-->
<script type="text/javascript" src="https://www.google.com/jsapi"></script>
<script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script type="text/javascript">
// Load the Visualization API and the gantt chart package.
google.load("visualization", "1", {packages: ["timeline"]});
// Set a callback to run when the Google Visualization API is loaded.
google.setOnLoadCallback(drawChart);
function drawChart() {
$.ajax({
url: "http://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, options);
}
</script>
</head>
<body>
<div id="chart_div" style="width: 900px; height: 200px;></div>
</body>
</html>
//加载可视化API和甘特图包。
load(“可视化”、“1”、{packages:[“timeline”]});
//将回调设置为在加载Google Visualization API时运行。
setOnLoadCallback(drawChart);
函数绘图图(){
$.ajax({
url:“http://localhost:8080/index1.php",
数据类型:“json”,
async:false,
成功:功能(数据){
jsonData=数据;
}
});
//使用从服务器加载的JSON数据创建我们的数据表。
var data=新的google.visualization.DataTable(jsonData);
//实例化并绘制图表,传入一些选项。
var chart=newgoogle.visualization.Timeline(document.getElementById('chart_div');
图表绘制(数据、选项);
}
试试这个,我想你在错误的地方访问了jsonData
<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>
$(函数(){
//加载可视化API和piechart包。
load('visualization','1',{'packages':['corechart']});
//将回调设置为在加载Google Visualization API时运行。
setOnLoadCallback(drawChart);
函数绘图图(){
$.ajax({
url:“localhost:8080/index1.php”,
数据类型:“json”,
async:false,
成功:功能(数据){
jsonData=数据;
//使用从服务器加载的JSON数据创建我们的数据表。
var data=新的google.visualization.DataTable(jsonData);
//实例化并绘制图表,传入一些选项。
var chart=newgoogle.visualization.Timeline(document.getElementById('chart_div');
绘制图表(数据,{宽度:500,高度:240});
}
})
};
});
我想你有数据
格式问题,试试这个
你错过了:“在div风格上
<div id="chart_div" style="width: 900px; height: 200px;></div>
它修复了我的一些错误。我得到GET@ArunKumar没有得到你面临的错误,你能粘贴errorGET这是我在谷歌chrome的控制台页面上看到的,因为我仍然得到一个空白页面我修复了,但它给我一个错误无效的数据表格式:3或4列
<div id="chart_div" style="width: 900px; height: 200px;></div>