Using Ruby Hash instead of Rails ActiveRecord in Coffeescript / Morris.JS
Posted
by
Vanessa L'olzorz
on Stack Overflow
See other posts from Stack Overflow
or by Vanessa L'olzorz
Published on 2012-11-23T22:49:14Z
Indexed on
2012/11/23
23:04 UTC
Read the original article
Hit count: 379
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!
© Stack Overflow or respective owner