user1011444
user1011444

Reputation: 1399

How to use Time in Google Charts?

I'm using Google Charts. Here's an example data from Google's website:

var data = new google.visualization.DataTable(
   {
     cols: [{id: 'task', label: 'Employee Name', type: 'string'},
            {id: 'startDate', label: 'Start Date', type: 'date'}],
     rows: [{c:[{v: 'Mike'}, {v: new Date(2008, 1, 28), f:'February 28, 2008'}]},
            {c:[{v: 'Bob'}, {v: new Date(2007, 5, 1)}]},
            {c:[{v: 'Alice'}, {v: new Date(2006, 7, 16)}]},
            {c:[{v: 'Frank'}, {v: new Date(2007, 11, 28)}]},
            {c:[{v: 'Floyd'}, {v: new Date(2005, 3, 13)}]},
            {c:[{v: 'Fritz'}, {v: new Date(2011, 6, 1)}]}
           ]
   }
)

I'd like to use hours and minutes also in the date variables. I haven't found an example syntax on the website, has anyone tried this before? Thanks in advance.

Upvotes: 1

Views: 1525

Answers (1)

Jeremy Visser
Jeremy Visser

Reputation: 6621

The Mozilla Developer Network has an extensive JavaScript reference, including on the Date object. See the following constructor syntax:

new Date()
new Date(milliseconds)
new Date(dateString)
new Date(year, month, day [, hour, minute, second, millisecond ])

So for 2011-06-01 at 1:37 PM, you could do:

new Date(2011, 5, 1, 13, 37)

Please note that months are zero-based, so the 5 above represents the 6th month (i.e. June).


N.B. I have very little familiarity with Google Charts, so I would accept edits to make this question more relevant to the O.P.'s question.

Upvotes: 1

Related Questions