Module: Charting::ActiveRecordArray::InstanceMethods

Defined in:
lib/ar_to_chart/active_record_array.rb

Instance Method Summary collapse

Instance Method Details

#to_chart(columns, label_column, options = {}) ⇒ Object

Render a chart based upon an ActiveRecord result set. Requires jQuery.

Parameters

columns:        column name (or array of names) representing the
                Y-Axis
label_column:   The category (X-Axis) column

Options

See the options in Charting::Highcharts::Renderer


25
26
27
# File 'lib/ar_to_chart/active_record_array.rb', line 25

def to_chart(columns, label_column, options = {})
  chart_object(columns, label_column, options).to_html
end

#to_container_and_script(column, label_column, options = {}) ⇒ Object

Returns the chart container (the <div>) and the javascript separately so you can put the container where you want and the javascript at the end of the document



32
33
34
35
# File 'lib/ar_to_chart/active_record_array.rb', line 32

def to_container_and_script(column, label_column, options = {})
  chart = chart_object(column, label_column, options)
  return chart.container, chart.script
end

#to_sparkline(column, options = {}) ⇒ Object

Render a sparkline based upon an ActiveRecord result set. Requires jQuery and jQuery sparklines plugin.

Parameters

column:         column name representing the
                Y-Axis
label_column:   The category (X-Axis) column

Options

See the options in Charting::Sparklines::Renderer


49
50
51
# File 'lib/ar_to_chart/active_record_array.rb', line 49

def to_sparkline(column, options = {})
  sparkline_object(column, options).to_html
end