Odd bug with Jquery

2,724 views
Skip to first unread message

Maxus

unread,
Dec 19, 2011, 3:17:24 AM12/19/11
to Google Visualization API
Hi People,

I have a chart on my page:

<div id="list_active_value_card_accounts_table" class="graph"></div>

<script type="text/javascript">

function requestListActiveValueCardAccounts() {

var chartHolder = $('#list_active_value_card_accounts_table');

$.ajax({
url: '@Url.Content("~/endpoint/
ListActiveValueCardAccounts")',
dataType: 'json',
data: { limit: 10 },
cache: false,
success: function (result) {
var data = new google.visualization.DataTable(result);
var table = new
google.visualization.Table(chartHolder[0]);
table.draw(data, { showRowNumber: false,
cssClassNames: { tableCell: 'tablefontclass', headerCell:
'tablefontclass'} });

}
});
}
</script>

my Json:

{"cols":[{"id":"Debit","label":"Debit","type":"number"},
{"id":"Credit","label":"Credit","type":"number"},
{"id":"Balance","label":"Balance","type":"number"},
{"id":"ValueCard","label":"ValueCard","type":"string"},
{"id":"CallDate","label":"CallDate","type":"datetime"}],"rows":[{"c":
[{"v":6.75},{"v":20},{"v":13.25},{"v":"280210753455"},{"v": "new
Date(2011,11,19,8,9,13)"}]}]}


The chart fails to show because of Jquery already parsing the dates
into javascript date time, before it is handled by the datatable. The
error I get from jquery is: Object doesn't support property or method
'getTimezoneOffset' and the chart isn't drawn. This appears to be the
same issue these people are getting:

http://www.ram-solutions.nl/?tag=google-charts-api
http://stackoverflow.com/questions/2823478/populate-google-visualization-datatable-for-a-annotatedtimeline-using-json

Nothing I do seems to fix the issue, has anyone else come across this
or know how to fix it?

I'm using jquery-1.5.1.min.js

Thanks Heaps,
Maxus

asgallant

unread,
Dec 19, 2011, 12:34:39 PM12/19/11
to google-visua...@googlegroups.com
jQuery shouldn't be parsing the date data into a javascript date object, as date objects are not part of the JSON spec - they should be parsed as strings.  Are you sure it's jQuery throwing the error?

Maxus

unread,
Dec 19, 2011, 7:00:30 PM12/19/11
to Google Visualization API
Hi Asgallant,

Your right, I just removed all the jquery references and passed the
json statically to the datatable method, it now crashes in the middle
of (Corechart.I.js).

Any ideas why it would be doing that? Is there a way to get a
debugging version of the google code?

Thanks,
A

asgallant

unread,
Dec 19, 2011, 7:25:35 PM12/19/11
to google-visua...@googlegroups.com
You need to get rid of the 'new' before your Date.  See: http://jsfiddle.net/G82Et/

Maxus

unread,
Dec 19, 2011, 8:34:02 PM12/19/11
to Google Visualization API
Hi Asgallant,

I found the issue:

if I change this: {"v": "new Date(2011,11,19,8,9,13)"} to {"v":
"Date(2011,11,19,8,9,13)"} all works fine :)

Thanks for your help!

Cheers,
M

> > strings.  Are you sure it's jQuery throwing the error?- Hide quoted text -
>
> - Show quoted text -

Reply all
Reply to author
Forward
0 new messages