0

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": "AnnotatedTimeLine",
 }
</script>

Any ideas would be hugely appreciated.

David.

1 Answers1

1

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
},
Anuj Balan
  • 7,629
  • 23
  • 58
  • 92
andras.tim
  • 1,964
  • 1
  • 13
  • 23