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

Wrong position when rendering chart template multiple times on the same page

hagitgit opened this issue · comments

Hello,

When rendering the same chart partial multiple times on the same page, the second chart is rendered on top of the first one.

index.html.erb

<div id="container-with-size1">
  <%= render :partial => 'chart', :locals => {:chart => @chart1} %>
</div>
<div id="container-with-size2">
  <%= render :partial => 'chart', :locals => {:chart => @chart2} %>
</div>

_chart.html.erb

<script src='http://www.google.com/jsapi'></script>
<div id='chart'></div>
<%= render_chart(chart, 'chart') %>

chart2 is rendered inside the first container, on top of chart1.

Thank you.

Every chart needs a unique CSS #id. But because you are using a partial, every one of them tries to load itself in #chart.

Also, you don't have to put
<script src='http://www.google.com/jsapi'></script>
in every partial. Just load it once in your head tag and that is enough.

Hope this helps.

OK. Thanks.