6

我安装了 chartkick 1.2.0 和 groupdate 1.0.4 gem。当我尝试做某事时:

  <%= area_chart Match.group_by_day_of_week(:created_at).count, :width=>"700px;", :height=>"150px;"  %>

我明白了:

在此处输入图像描述

它总是给我错误的y轴。我应该如何格式化它才能显示“星期一”,“星期二”......

我的第二个例子,我也做不好,是一天中按小时分组。

  <% abc=Matches.on_location(@location).group_by{|b| b.created_at.strftime("%H").to_i} %>
  <% abc.update(abc){|key, v| v.length} %>
  <%= abc=abc.sort_by{|k,v| k} %>
  <%= area_chart abc, :width=>"700px;", :height=>"150px;"  %>

我做错了什么,它显示 1:00:00 AM 等?我只想有数字,即:0、1、2、3 .. 23?

我四处搜索,从上到下检查了他们的文档:http: //ankane.github.io/chartkick/几个小时,我真的不知道我错过了什么。任何帮助将不胜感激!

4

2 回答 2

2

This thread on Chartkick's Github indicates that the charting library (Highcharts, in your case?) makes assumptions about what kind of X-axis you want. At a guess, I would say that the issue here is that the library is making an incorrect assumption, so try naming your input's keys in a more obvious format.

In your first example, you could try using the "Monday", "Tuesday", etc as keys instead of 0, 1, etc:

results = Match.group_by_day_of_week(:created_at).count # hash with numeric keys
days = %w(Monday Tuesday Wednesday Thursday Friday Saturday Sunday)
results = results.inject({}){|a, (k,v)| a.update(days[k] => v); a } # change numeric keys to weekday name

For the second example, try formatting the date as %H:%M:%S so it's more obvious that you want a time axis:

abc=Matches.on_location(@location).group_by{|b| b.created_at.strftime("%H:%M:%S")}
于 2013-10-30T22:42:14.773 回答
1

不幸的是,现在没有办法做到这一点。作为替代方案,您可以尝试使用柱形图。

于 2013-11-03T08:19:29.123 回答