【问题标题】:Rails and ChartkickRails 和 Chartkick
【发布时间】:2013-08-06 06:43:46
【问题描述】:

我正在尝试将此样式图表实现到我的 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?我已经阅读了文档,并不能完全掌握它。 谢谢!

【问题讨论】:

    标签: ruby-on-rails ruby charts


    【解决方案1】:

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

    <%= 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] }}
    ] %>
    

    【讨论】:

    • 当我输入此代码时,我得到一个错误:语法错误,意外']',期待'}'任何线索为什么?
    • @TonyTambe 这是一个 ruby​​ 语法错误。尝试在哈希之外初始化数组,然后将其作为数据键的值插入,该错误应该会消失。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-04-03
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多