开发者

Error with zoomStartTime and AnnotatedTimeLine

I'm a bit of a beginner with Javascript, but last month I had a working Google chart linked to a Google Docs file, which uses a start date for the graph at 90 days before the current date.

I checked the page today and in Chrome I get the message "Object # has no method 'getTime'", and in Firefox I get the message "b.zoomStartTime[y] is not a function". Both stop the graph from loading.

I have simplified the code to help me with the error, but I'm not getting anywhere... Here's the code:

<script type="text/javascript">
    var oldDate = new Date();
    oldDate.setDate(oldDate.getDate() - 90);
</script>       

<script type="text/javascript" src="//ajax.googleapis.com/ajax/static/modules/gviz/1.0/chart.js">
 {
     "dataSourceUrl": "//docs.google.com/spreadsheet/tq?key=0AkQH6d2CUv_qdDhwd3gtZzdTVFlNX3AwX2xUSUVuclE&transpose=0&headers=-1&range=A1%3AB2436&gid=0&pub=1",
     "options": {
         "zoomStartTime": oldDate,              
         "width": 650,
         "height": 371
     },
     "chartType": "A开发者_如何学PythonnnotatedTimeLine",
 }
</script>

Any ideas would be hugely appreciated.

David.


The getDate() call returns the day of the month (http://www.w3schools.com/jsref/jsref_obj_date.asp), which creates an invalid date and causes the error.

A solution for get another date than now:

function getDate(y, m, d) {
    var now = new Date();
    return new Date(now.getFullYear()+(y?y:0), now.getMonth()+(m?m:0), now.getDate()+(d?d:0));
}

You may use like this:

"options": {
    "zoomStartTime": getDate(0, -90, 0),              
    "width": 650,
    "height": 371
},
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜