简体   繁体   中英

Passing Date field to google chart timeline

I would like to populate the Google chart timeline on my app using Ruby on Rails and the problem that I have is how to pass date to addrows([new Date()]]. Any hint is greatly appreciated.

Below is the sample code

var dataTable = new google.visualization.DataTable();
dataTable.addColumn({ type: 'string', id: 'Position' });
dataTable.addColumn({ type: 'string', id: 'Name' });
dataTable.addColumn({ type: 'date', id: 'Start' });
dataTable.addColumn({ type: 'date', id: 'End' });
dataTable.addRows([
[ 'book id','book title', new Date(2013, 1, 1), new Date(2013, 10,1)],]]);
chart.draw(dataTable);
}
</script>

<div id="example3.1" style="width: 1000px; height: 200px;"></div>

you can do this way

dataTable.addRows([
[ 'book id','book title', <%= Time.now %>, <%= Time.now %>,]]);

More hint is here depending on your requirement --> Ruby Time format

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM