I'm working on a dashboard app using Rails 3.1.1/Highcharts with several graphs, but am stuck on converting a date string from the rails model into a javascript format that highcharts can accept.
My sample code:
<%= @orders.map{ |f| [f.date, f.units.to_f] }.inspect %>
Produces this output:
[[Fri, 04 Nov 2011, 182.0], [Sun, 06 Nov 2011, 189.0], [Tue, 08 Nov 2011, 178.0], [Thu, 10 Nov 2011, 115.0], [Sat, 12 Nov 2011, 135.0], [Mon, 14 Nov 2011, 120.0], [Thu, 17 Nov 2011, 181.0], [Sun, 20 Nov 2011, 145.0]]
I need to have the date format of the array as follows:
Date.UTC(2010, 10, 4).
Any suggestions on an existing rails/ruby method or how to create a helper?
This probably isn't the best way to do this, but I've been doing:
data: <%= @orders.map{ |f| [f.date.to_datetime.to_i, pdd.field_5x5 ] }.inspect %>,
...which expresses the date in seconds.
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.