Class: Chartify::WebChart::GoogleChart::PieChart

Inherits:
PieChart show all
Includes:
GoogleChartModule
Defined in:
lib/chartify/web_chart/google_chart/pie_chart.rb

Instance Attribute Summary

Attributes inherited from ChartBase

#columns, #data, #label_column, #title

Instance Method Summary collapse

Methods included from GoogleChartModule

#array_data_table, #chart_options, #include_js, #timestamp, #wrap_in_function

Methods inherited from PieChart

#initialize, #to_blob

Methods inherited from ChartBase

#add_row, evaluate_js, #initialize, #render_chart

Constructor Details

This class inherits a constructor from Chartify::PieChart

Instance Method Details

#render(html_dom_id) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/chartify/web_chart/google_chart/pie_chart.rb', line 9

def render(html_dom_id)
  datasets = data.collect do |column|
    if column.kind_of?(Array)
      title, val = column[0], column[1]
    else
      title, val = column, column.to_s.humanize
    end
    [title, val]
  end
  insert_title_row(datasets)

  js = <<-JS
    var data = google.visualization.arrayToDataTable(#{datasets.to_json});
    var chart = new google.visualization.PieChart(document.getElementById('#{html_dom_id}'));
    chart.draw(data, #{chart_options.to_json});
  JS
  wrap_in_function(js).html_safe
end