1

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!

Vanessa L'olzorz
  • 1,325
  • 3
  • 10
  • 10

1 Answers1

0

Following the Morris.JS examples here I suppose you have to change your data hash a little bit.

{'purchased_at' => 2009, 'value' =>1000}
{'purchased_at' => 2010, 'value' =>2000}
...

Then in Coffee:

jQuery ->
  Morris.Line
    element: 'orders_chart'
    data: $('#orders_chart').data('orders')
    xkey: 'purchased_at'
    ykeys: ['value']
    labels: ['Price']
awenkhh
  • 5,811
  • 1
  • 21
  • 24