0

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???

Evgeny Palguev
  • 599
  • 3
  • 18

1 Answers1

0

Maybe they changed the API since this question, but they show an example of a multi line series. http://chartkick.com/

<%= line_chart Feat.group(:goal_id).group_by_week(:created_at).count %>

So try

<%= line_chart @company.group(:symbol).group_by_day(:current_date).count %>

You are grouping by the current_date instead of :created_at, which is all set to the same value:

company.current_date = stock.Date

I don't know what that will return, because it doesn't look like an attribute value. I get undefined method Date error.

Chloe
  • 25,162
  • 40
  • 190
  • 357