我正在关注 RailsCasts 的图表教程,但我在添加自己的数据时遇到了一些问题。当我尝试添加数据时,图表不显示。
我能够使用来自 morris.js 的示例脚本来显示图表。我已经用这一行设置了我的 index.html.erb 文件:
<%= content_tag :div, "", id: "stats_chart", data: {stats: @stats} %>
div源码如下:
< div data-stats="[{"id":1,"attendance":121,"salvations":12,"visitors":32,"offering":"234234.0","created_at":"2013-07- 17T05:33:28.785Z","updated_at":"2013-07-17T05:33:28.785Z","campus_id":1,"date":"2013-07-14","time":"2000- 01-01T19:00:00Z"},{"id":2,"attendance":1212,"salvations":1,"visitors":21,"offering":"123123.0","created_at":"2013- 07-18T03:06:02.583Z","updated_at":"2013-07-18T03:06:02.583Z","campus_id":1,"date":"2013-07-07","time":" 2000-01-01T17:00:00Z"},{"id":3,"attendance":234,"salvations":2,"访客":24,"offering":"2345.0","created_at":"2013-07-18T03:15:12.613Z","updated_at":"2013-07-18T03:15:12.613Z","campus_id" :1,"日期":"2013-06-30","时间":"2000-01-01T19:00:00Z"}]" id="stats_chart">
我的咖啡脚本文件是:
jQuery ->
Morris.Line
element: 'stats_chart'
$('#stats_chart').data('stats')
xkey: 'date'
ykeys: ['attendance']
labels: ['attendance']
我猜我的问题出在咖啡脚本中,但我不知道是什么。如果有帮助,我正在使用 Rails 4。我究竟做错了什么?或者我需要改变什么?