Chartkick and groupdate gems are show only one point at graph, graph should be several lines

I create ruby on rails app to show stock value for some companies at some time period. I use next gems: chartkick, groupdate and stock_quote

My Shema.db:

  create_table "companies", force: :cascade do |t|
    t.string   "symbol"
    t.datetime "current_date"
    t.float    "value"
    t.datetime "created_at",   null: false
    t.datetime "updated_at",   null: false
  end

Fill database with seeds.rb:

Company.delete_all
d1 = Date.new(2014, 9, 1)
d2 = Date.new(2015, 9, 1)

stocks = StockQuote::Stock.history("aapl", d1, d2)
stocks.each do |stock|
    company = Company.new
    company.symbol = stock.Symbol.to_s
    company.current_date = stock.Date
    company.value = stock.Volume
    company.save
end

stocks = StockQuote::Stock.history("tsla", d1, d2)
stocks.each do |stock|
    company = Company.new
    company.symbol = stock.Symbol.to_s
    company.current_date = stock.Date
    company.value = stock.Volume
    company.save
end

stocks = StockQuote::Stock.history("yhoo", d1, d2)
stocks.each do |stock|
    company = Company.new
    company.symbol = stock.Symbol.to_s
    company.current_date = stock.Date
    company.value = stock.Volume
    company.save
end

In controller:

  def show
    @company = Company.all
  end

In show.html.erb I put code from http://ankane.github.io/chartkick/:

<div class="row">
  <div class="col-xs-12">
    <h3>Values By Day 2 years by companies</h3>
    <%= line_chart @company.group(:symbol).group_by_day(:current_date, format: "%B %d, %Y").count, discrete: true %>
  </div>
</div>

The graph should be several lines, and have only ONE point at graph:

enter image description here

What should i do, change, add???


Source: ruby

Leave a Reply