jeremyolliver / gvis

Rails plugin for easy embedding charts with Google Visualization API
http://github.com/jeremyolliver/gvis
MIT License
49 stars 22 forks source link

Can this work with rjs? #2

Closed dkitchel closed 14 years ago

dkitchel commented 14 years ago

I'm trying to use geomaps which render perfectly fine on the page, but I'm trying to pass a parameters to an rjs page which does a page replace to swap the old geomap for a new one from a partial. The partial works perfectly fine if I render it on the first page call, but if I render it via rjs with a form_remote_tag, it doesn't work. Any ideas?

jeremyolliver commented 14 years ago

Interesting, I haven't tried that before. The packages for each specific graph type have to be loaded first, which is done as part of the render_visualizations call. Are you calling this from your rjs partial? What does the code look like that you're using?

Cheers, Jeremy

dkitchel commented 14 years ago

Here's the full circle.

The form I'm using looks like this

<% form_remote_tag :url=>'/admin/athletes/charts/gvmaps/', :method =>"post" do -%> Days ago: <%= text_field_tag(:days, value='all') %> Type: <%= text_field_tag(:type, value='all') %> <%= submit_tag("Report") %> <% end -%>

The rjs code looks like this

page.replace_html 'maps_gv', :partial => 'maps_gv', :params => {:days => params[:days], :type => params[:type]}

And the partial code looks like this

<%= include_visualization_api %> <%= render_visualizations %>

<% @riders = AdminReportsData.ridersGV(params[:days],params[:type]) %>

<% visualization "rider_map", "GeoMap", :width => 800, :height => 400, :region => "'US'", :colors =>"[0xE0FFD4, 0xc06000]" do |chart| %> <% chart.string "State" %> <% chart.number "Recruits" %> <% loopcount = 0 @riders.each do chart.add_row([@riders[loopcount][:state].to_s,@riders[loopcount][:num].to_i]) loopcount += 1 end %>

<% end %>

Anything else I put on the partial is rendered fine, but no geomap.

Thanks for your help on this!

jeremyolliver commented 14 years ago

Try putting the <%= include_visualization_api %> <%= render_visualizations %> calls after the chart. It relies on visualization having already been called first. When it's in the layout and the visualization call is in a view the view gets rendered before the layout I'm pretty sure.

jeremyolliver commented 14 years ago

closing old issue