Module: RailsHighchartsHelper

Defined in:
app/helpers/rails_highcharts/rails_highcharts_helper.rb

Instance Method Summary collapse

Instance Method Details

#high_chart(placeholder, object, &block) ⇒ Object

ActiveSupport::JSON.unquote_hash_key_identifiers = false



3
4
5
6
7
# File 'app/helpers/rails_highcharts/rails_highcharts_helper.rb', line 3

def high_chart(placeholder, object  , &block)
  object.html_options.merge!({:id=>placeholder})
  object.options[:chart][:renderTo] = placeholder
  high_graph(placeholder, object, &block).concat(("div", "", object.html_options))
end

#high_graph(placeholder, object, &block) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'app/helpers/rails_highcharts/rails_highcharts_helper.rb', line 9

def high_graph(placeholder, object, &block)
graph =<<-EOJS
<script type="text/javascript">
jQuery(function() {
  // 1. Define JSON options
  var options = { chart:       #{object.options[:chart].to_json},
                  title:       #{object.options[:title].to_json},
                  legend:      #{object.options[:legend].to_json},
                  xAxis:       #{object.options[:x_axis].to_json},
                  yAxis:       #{object.options[:y_axis].to_json},
                  tooltip:     #{object.options[:tooltip].to_json},
                  credits:     #{object.options[:credits].to_json},
                  plotOptions: #{object.options[:plot_options].to_json},
                  series:      #{object.data.to_json},
                  subtitle:    #{object.options[:subtitle].to_json}
  };

  // 2. Add callbacks (non-JSON compliant)
  #{capture(&block) if block_given?}
  // 3. Build the chart
  var chart = new Highcharts.Chart(options);
  });
  </script>
  EOJS
  if defined?(raw) &&  Rails.version.to_i >= 3
    return raw(graph) 
  else
    return graph unless block_given?
    concat graph
  end
end