jac*_*ton 2 javascript datetime json google-visualization
我在尝试使用Google Charts API构建带注释的时间线图时遇到问题.
在JSON中,对于第一个"日期"列,如果我使用:
"v": new Date(2010, 01, 01)
然后我从我的页面收到一个JavaScript错误,说我有无效的JSON.
如果相反我使用:
"v": "new Date(2010, 01, 01)"然后我得到了错误TypeError: 'undefined' is not a function (evaluating 'M[y]()').
我的JavaScript代码只是对Pie Graph的示例代码的修改,该代码位于:http://code.google.com/apis/chart/interactive/docs/php_example.html
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Strict//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<!--Load the AJAX API-->
<script type="text/javascript" src="https://www.google.com/jsapi"></script>
<script type="text/javascript" src="scripts/jquery-1.6.2.js"></script>
<script type="text/javascript">
// Load the Visualization API and the piechart package.
google.load('visualization', '1', {'packages':['annotatedtimeline']});
// Set a callback to run when the Google Visualization API is loaded.
google.setOnLoadCallback(drawChart);
function drawChart() {
var jsonData = $.ajax({
url: "getData.php",
dataType:"json",
async: false
}).responseText;
// 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.AnnotatedTimeLine(document.getElementById('chart_div'));
chart.draw(data, {width: 400, height: 240});
}
</script>
</head>
<body>
<!--Div that will hold the pie chart-->
<div id="chart_div" style="height: 200px; width:200px;"></div>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
我知道人们有类似的问题:
http://groups.google.com/group/google-visualization-api/browse_thread/thread/4cfe7f07e5ef4bcc
http://www.mail-archive.com/google-visualization-api@googlegroups.com/msg02940.html
但是在这些线程/页面中,答案似乎是使用"v": new Date(2010, 01, 01)但是这对我不起作用.
我不确定我在这里缺少什么.
谢谢
所以我最终在Google Visualization API用户组的帮助下弄明白了.
这两个都验证为JSON并在使用时正确呈现"v": "Date(2010, 01, 01)"- 请注意缺少"new"关键字.
希望这有助于将来的其他人.
| 归档时间: |
|
| 查看次数: |
2775 次 |
| 最近记录: |