我假设您正在尝试显示过去 7 天内每天的新用户数。如果是这样,您可以执行以下操作
控制器代码
# declare a struct to hold the results
UserCountByDate = Struct.new(:date, :count)
def report
@user_counts = User.count( :group => "DATE(created_at)",
:conditions => ["created_at >= ? ", 7.days.ago],
:order => "DATE(created_at) ASC"
).collect do |date, count|
UserCountByDate.new(date, count)
end
end
查看代码
<div id="chart"></div>
<%= Seer::visualize(
@user_counts,
:as => :column_chart,
:in_element =>'chart',
:series => {
:series_label => 'date',
:data_method => 'count'
},
:chart_options => {
:height => 300,
:width => 100 * @user_counts.size,
:is_3_d => true,
:legend => 'none',
:colors => "[{color:'#990000', darker:'#660000'}]",
:title => "New users in last 7 days",
:title_x => 'date',
:title_y => 'count'
}
)
-%>
data_method
应该出现在用作图表输入的数组的每一行中。该方法返回一个散列,该散列被转换为响应和方法ActiveRecord count
的数组。struct
date
count