2012-11-23 37 views
1

我遵循Railscast #223的介紹Morris.JS在Coffeescript/Morris.JS中使用Ruby Hash代替Rails ActiveRecord

我產生我的控制器在我看來,我有以下的嘗試和渲染圖形叫@orders_yearly數據集:

<%= content_tag :div, "", id: "orders_chart", data: {orders: @orders_yearly} %> 

調用@orders_yearly.inspect顯示它只是一個簡單的哈希:

{2009=>1000, 2010=>2000, 2011=>4000, 2012=>100000} 

我需要修改咖啡腳本中的xkeyykeys的值才能工作,但我不確定如何使其與我的數據集一起工作:

jQuery -> 
    Morris.Line 
    element: 'orders_chart' 
    data: $('#orders_chart').data('orders') 
    xkey: 'purchased_at' # <------------------ replace with what? 
    ykeys: ['price'] # <---------------------- replace with what? 
    labels: ['Price'] 

任何人有任何想法?

謝謝!

回答

0

Morris.JS examples here我想你必須稍微改變你的數據散列。

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

然後在咖啡:

jQuery -> 
    Morris.Line 
    element: 'orders_chart' 
    data: $('#orders_chart').data('orders') 
    xkey: 'purchased_at' 
    ykeys: ['value'] 
    labels: ['Price'] 
相關問題