Help with proper graph creation using chartkick and sinatra

Hello,

I’m trying to use Chartkick[1] to generate a graph for a Sinatra
application. The graph I would like to generate is one that shows the
variation of price over time for each store.

The code I’d like to emulate is this:

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

I have made a helper which produces the following data (cli output):

cat test.rb
require_relative ‘pritory’
a = Product.last.source # returns array
MyHelpers.make_graph(a).each do |name, data|
puts “name: #{name}, data: #{data}”
end

ruby test.rb
name: MyStore, data: [{:price=>32.0, :date=>2014-08-30 17:11:44 +0200},
{:price=>30.0, :date=>2014-09-08 22:07:20 +0200}, {:price=>32.0,
:date=>2014-09-08 22:07:41 +0200}, {:price=>31.0, :date=>2014-09-08
22:07:55 +0200}]
name: Store1, data: [{:price=>37.0, :date=>2014-09-05 23:19:35 +0200}]
name: Store2, data: [{:price=>42.0, :date=>2014-09-08 22:00:46 +0200}]
name: Store3, data: [{:price=>45.0, :date=>2014-09-08 22:09:30 +0200}]

Here is the line in the views in HAML:

= line_chart MyHelpers.make_graph(@product.source).map {|name, data|
{name: name, data: data.group_by_day(:date).price } }

The error I’m getting is: “no implicit conversion of Symbol into
Integer” (TypeError).

Since I’m probably generating the wrong kind of data format, any ideas
on how to approach this, would be more than welcomed. Lost almost one
day over this!

Thanks for your time!

[1] http://ankane.github.io/chartkick/

Panagiotis (atmosx) Atmatzidis

email: [email protected]
URL: http://www.convalesco.org
GnuPG ID: 0x1A7BFEC5
gpg --keyserver pgp.mit.edu --recv-keys 1A7BFEC5

“As you set out for Ithaca, hope the voyage is a long one, full of
adventure, full of discovery […]” - C. P. Cavafy