Generating bubble chart using lazy_high_charts

351 views Asked by At

I'm pretty new to JavaScript, Ruby, Rails and Highcharts, but I have muddled through well enough to get line and pie charts working using rails 4 and the lazy_high_charts gem version 1.5.0. I can't figure out how to get a bubble chart to appear though. :( I don't see any errors reported in my rails server log (which I think makes sense, since the problems would manifest client side). I can't figure out if there is a client side log. Can anyone point out my no-doubt noob mistake?

Here is my controller code:

bubble_series = [[1,2,3], [4,5,6]]
@chart = LazyHighCharts::HighChart.new('bubble') do |f|
  f.title(text: 'Bubbles!')            
  f.chart(type: 'bubble', zoomType: 'xy', plotBorderWidth: 1) 
  f.series(
    data: bubble_series,
    marker: {
      fillColor: {
        radialGradient: { cx: 0.4, cy: 0.3, r: 0.7 },
        stops: [ [0, 'rgba(255,255,255,0.5)'], [1, 'rgba(69,114,167,0.5)'] ]
     }
   }
 )
end

and in my view, its referenced as:

<div class="span8">
  <% if @readings.any? %>
    <%= high_chart("chart", @chart) %>
  <% end %>
</div>

Thanks!!

[Edit] Doh. I figured out which noob thing I did. I failed to include the highcharts-more script on the generated page. It worked once I added this line to the section of my application layout .html.erb file:

<%= javascript_include_tag "highcharts-more" %>

I'll close my question once I'm allowed to (in ~5 hours).

2

There are 2 answers

0
user3079032 On

Doh. I figured out which noob thing I did. I failed to include the highcharts-more script on the generated page. It worked once I added this line to the section of my application layout .html.erb file:

<%= javascript_include_tag "highcharts-more" %>
0
andrew2005 On

For reference, I had the same issue. The graph wasn't appearing but I was seeing an 'undefined function' in the javascript console.

My problem was that I was using an old version of highcharts that didn't support the bubble graph properly.

If you're using lazy_high_charts > 1.5.1, you can get the latest highcharts version by running:

rake highcharts:update

Make sure you remove the old files is they're in a different location.