winston / google_visualr

A Ruby Gem for the Google Visualization API. Write Ruby code. Generate Javascript. Display a Google Chart.

Home Page:http://googlevisualr.heroku.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Possible reopen of sinatra #31

neilyoung opened this issue · comments

Having the same setup and getting

undefined method `to_json' for {:type=>"string", :label=>"Year"}:Hash
file: data_table.rb location: display line: 231

(Mac OSX Yosemity, ruby 1.9.2 and 2.0). Any pointer?

Here is the single file:

require 'google_visualr'
require 'sinatra'

template :layout do
<<LAYOUT
<html>
<head>
<title>Sinatra Google Chart</title>
<script src='https://www.google.com/jsapi'></script>
</head>
<body>
<%= yield %>
</body>
</html>
LAYOUT
end

template :index do
<<INDEX
<center>

<p>
<div id='chart'></div>
<%= @chart.to_js("chart") %>
</p>
</center>
INDEX
end

get '/' do
  data_table = GoogleVisualr::DataTable.new
  # Add Column Headers
  data_table.new_column('string', 'Year')
  data_table.new_column('number', 'Sales')
  data_table.new_column('number', 'Expenses')
  # Add Rows and Values
  data_table.add_rows([
                          ['2004', 1000, 400],
                          ['2005', 1170, 460],
                          ['2006', 660, 1120],
                          ['2007', 1030, 540]
                      ])
  option = { width: 400, height: 240, title: 'Company Performance' }
  @chart = GoogleVisualr::Interactive::AreaChart.new(data_table, option)

  erb :index

end  

Oh, too stupid.

require 'JSON' was missing.

Closed.