var legend = new AmCharts.AmLegend;
<% builder.render_settings(legend, 'legend') %>
<%= yield(legend, 'legend') rescue nil %>
<% builder.render_listeners(legend, 'legend') %>
chart.addLegend(legend, <%= builder.to_js(div) %>);
var legend = new AmCharts.AmLegend;
<% builder.render_settings(legend, 'legend') %>
<%= yield(legend, 'legend') rescue nil %>
<% builder.render_listeners(legend, 'legend') %>
<% if div.present? %>
  chart.addLegend(legend, <%= builder.to_js(div) %>);
<% else %>
  chart.addLegend(legend);
<% end %>

Fix legend positioning when legend_div is not specified
Fix legend positioning when legend_div is not specified
