Using Ruby Hash instead of Rails ActiveRecord in Coffeescript / Morris.JS
- by Vanessa L'olzorz
I'm following the Railscast #223 that introduced Morris.JS.
I generate a data set called @orders_yearly in my controller and in my view I have the following to try and render the graph:
<%= content_tag :div, "", id: "orders_chart", data: {orders: @orders_yearly} %>
Calling @orders_yearly.inspect shows it's just a simple hash:
{2009=>1000, 2010=>2000, 2011=>4000, 2012=>100000}
I'll need to modify the values for xkey and ykeys in coffeescript to work, but I'm not sure how to make it work with my data set:
jQuery ->
Morris.Line
element: 'orders_chart'
data: $('#orders_chart').data('orders')
xkey: 'purchased_at' # <------------------ replace with what?
ykeys: ['price'] # <---------------------- replace with what?
labels: ['Price']
Anyone have any ideas?
Thanks!