Chartkick列 - 数据不显示为条形

时间:2017-08-13 02:57:32

标签: ruby-on-rails chartkick

Chartkick的新手并不确定我哪里出错了。我有一张坦克表,有一个属性等级,我想在每个图表中显示坦克等级作为条形。

来自架构的坦克表:

_navigationService.NavigateAsync("FirstPage");

坦克控制器:

create_table "tanks", force: :cascade do |t|
  t.decimal "level"
  t.bigint "zipcode"
  t.bigint "tank_company_id"
  t.datetime "created_at", null: false
  t.datetime "updated_at", null: false
  t.index ["tank_company_id"], name: "index_tanks_on_tank_company_id"
end

查看:

def index
  @tanks = Tank.all
end

它如何显示在图表中,但图中没有条形图:

Chart, but no bars in the graph

1 个答案:

答案 0 :(得分:0)

您对column_chart的输入必须包含键和值,例如tank_company.id作为键,level作为值

div class="container text-center tanks-list">
  <div class="row">
    <% @tanks.each do |tank| %>
      <div class="col-md-4 tank">
        <p>Company: <%= tank.tank_company.name %></p>
        <p>Tank ID: <%= tank.id %></p>
        <p>Level: <%= tank.level.to_i %>%</p>
        <%= column_chart @tanks.group(:id).sum(:level), min: 0, max: 100 %>
      </div>
    <% end %>
  </div>
</div>