1

我正在尝试将此样式图表实施到我的 rails 项目中。

<%= line_chart @goals.map{|goal|
{:name => goal.name, :data => goal.feats.group_by_week(:created_at).count }
} %>

我目前正在使用 Chartkick 这样做。http://ankane.github.io/chartkick/ 这是我的表格的设置方式。

我想从我的 Timesheets 表的 3 列中跟踪 current_user Timesheets。

  def change
    create_table :timesheets do |t|
      t.decimal :teacher
      t.decimal :study
      t.decimal :conversation
      t.date :day
      t.references :user

      t.timestamps
    end
    add_index :timesheets, :user_id
  end

这就是我的时间表表目前的样子。我怎样才能通过chartkick通过图表跟踪:teacher、:study、:conversation?我已经阅读了文档,并不能完全掌握它。谢谢!

4

1 回答 1

4

如果我理解正确,你想做:

<%= line_chart [
  {name: "Teacher", data: current_user.timesheets.map{|t| [t.day, t.teacher] }},
  {name: "Study", data: current_user.timesheets.map{|t| [t.day, t.study] }},
  {name: "Conversation", data: current_user.timesheets.map{|t| [t.day, t.conversation] }}
] %>
于 2013-08-07T04:35:09.367 回答