sinatra #31

Closed
joaodrp opened this Issue Mar 20, 2012 · 4 comments

Comments

Projects
None yet
2 participants

joaodrp commented Mar 20, 2012

Hi,

Is there a way to make this work with a sinatra app? Cant get it to work.

Owner

winston commented Mar 20, 2012

I have not tried this with SInatra. May I know what is not working? Thanks!

joaodrp commented Mar 20, 2012

If in my sinatra app I do something like:

      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

Then in my view I do:

...
<div id='chart'></div>
      <%= render_chart(@chart, 'chart') %>  # => render_chart is not supported in sinatra
...

Probably I could get this to work if I can receive the chart image url, something like:

@chart = GoogleVisualr::Interactive::AreaChart.new(data_table, option).url

Then in my view I would be able to do at least this:

...
<div id='chart'></div>
     <img src= <%= @chart %>/>
...

Is it possible to make it compatible with sinatra?

Owner

winston commented Mar 20, 2012

The controller code looks correct to me, so I believe the reason it's not working is probably because render_chart does not exist in Sinatra. That method is a helper for Rails only.

Instead of using render_chart in your view, try this:

<div id='chart'></div>
<%= @chart.to_js("chart") %>

Let me know if this works. Thanks!

joaodrp commented Mar 20, 2012

Thanks, it works!

@joaodrp joaodrp closed this Mar 20, 2012

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment