I am trying to create a DataTable or DataArray on the server side (using spring/java) that can be used for google charts. The issue I'm facing is with the Date Format. Initially, I built a Data Array and serialized it to JSON, which looked like this:
{DataArray:[["Date","New York","Austin"],[100,200,300]]}
On the client side, parsing this DataArray to a DataTable was not a problem.
However, when I tried to add a Date, Angular threw an error because the json string was not well formatted in that case.
On the client side, I found a solution where I could convert an array into a DataTable using the following code:
data = new google.visualization.arrayToDataTable([ ['date','New York','Austin','San Francisco','Country','Popularity'], [new Date("8/6/1975"),2,3,15,'Germany',200], [new Date("8/6/1980"),5,6,19,'Brazil',400], [new Date("8/6/2000"),8,9,23,'United States',300], [new Date("8/6/2010"),11,12,35,'RU',700] ])
This method worked by using new Date(), but now I need to figure out how to create something like "new Date("8/6/1975")" on the server side and send it to the client so that it creates a Date Object on the client side.
Does anyone have any ideas on how I can achieve this? Can I use the json date format for this purpose? If so, how can I generate a json date on the server side that appears as "new Date("8/6/1975")" on the client side and converts into a Date object?