Class: Seer::PieChart
Overview
USAGE
In your controller:
@data = Widgets.all # Must be an array of objects that respond to the specidied data method
# (In this example, 'quantity'
In your view:
<div id="chart"></div>
<%= Seer::visualize(
@data,
:as => :pie_chart,
:series => {:series_label => 'name', :data_method => 'quantity'},
:chart_options => {
:height => 300,
:width => 300,
:axis_font_size => 11,
:title => "Widget Quantities",
:point_size => 5,
:is_3_d => true
}
)
-%>
For details on the chart options, see the Google API docs at code.google.com/apis/visualization/documentation/gallery/piechart.html
Constant Summary
Constants included from Chart
Chart::DEFAULT_COLORS, Chart::DEFAULT_HEIGHT, Chart::DEFAULT_LEGEND_LOCATION, Chart::DEFAULT_WIDTH
Instance Attribute Summary collapse
-
#background_color ⇒ Object
Chart options accessors.
-
#border_color ⇒ Object
Chart options accessors.
-
#data ⇒ Object
Graph data.
-
#data_method ⇒ Object
Graph data.
-
#data_table ⇒ Object
:nodoc:.
-
#enable_tooltip ⇒ Object
Chart options accessors.
-
#focus_border_color ⇒ Object
Chart options accessors.
-
#height ⇒ Object
Chart options accessors.
-
#is_3_d ⇒ Object
:nodoc:.
-
#label_method ⇒ Object
Graph data.
-
#legend ⇒ Object
Chart options accessors.
-
#legend_background_color ⇒ Object
Chart options accessors.
-
#legend_font_size ⇒ Object
Chart options accessors.
-
#legend_text_color ⇒ Object
Chart options accessors.
-
#pie_join_angle ⇒ Object
Chart options accessors.
-
#pie_minimal_angle ⇒ Object
Chart options accessors.
-
#title ⇒ Object
Chart options accessors.
-
#title_color ⇒ Object
Chart options accessors.
-
#title_font_size ⇒ Object
Chart options accessors.
-
#title_x ⇒ Object
Chart options accessors.
-
#title_y ⇒ Object
Chart options accessors.
-
#tooltip_font_size ⇒ Object
Chart options accessors.
-
#tooltip_height ⇒ Object
Chart options accessors.
-
#tooltip_width ⇒ Object
Chart options accessors.
-
#width ⇒ Object
Chart options accessors.
Attributes included from Chart
Class Method Summary collapse
-
.render(data, args) ⇒ Object
:nodoc:.
Instance Method Summary collapse
-
#initialize(args = {}) ⇒ PieChart
constructor
:nodoc:.
-
#nonstring_options ⇒ Object
:nodoc:.
-
#string_options ⇒ Object
:nodoc:.
-
#to_js ⇒ Object
:nodoc:.
Methods included from Chart
#data_columns, #formatted_colors, #in_element=, #options
Constructor Details
#initialize(args = {}) ⇒ PieChart
:nodoc:
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/seer/pie_chart.rb', line 42 def initialize(args={}) #:nodoc: # Standard options args.each{ |method,arg| self.send("#{method}=",arg) if self.respond_to?(method) } # Chart options args[:chart_options].each{ |method, arg| self.send("#{method}=",arg) if self.respond_to?(method) } # Handle defaults @colors ||= args[:chart_options][:colors] || DEFAULT_COLORS @legend ||= args[:chart_options][:legend] || DEFAULT_LEGEND_LOCATION @height ||= args[:chart_options][:height] || DEFAULT_HEIGHT @width ||= args[:chart_options][:width] || DEFAULT_WIDTH @is_3_d ||= args[:chart_options][:is_3_d] @data_table = [] end |
Instance Attribute Details
#background_color ⇒ Object
Chart options accessors
37 38 39 |
# File 'lib/seer/pie_chart.rb', line 37 def background_color @background_color end |
#border_color ⇒ Object
Chart options accessors
37 38 39 |
# File 'lib/seer/pie_chart.rb', line 37 def border_color @border_color end |
#data ⇒ Object
Graph data
40 41 42 |
# File 'lib/seer/pie_chart.rb', line 40 def data @data end |
#data_method ⇒ Object
Graph data
40 41 42 |
# File 'lib/seer/pie_chart.rb', line 40 def data_method @data_method end |
#data_table ⇒ Object
:nodoc:
40 41 42 |
# File 'lib/seer/pie_chart.rb', line 40 def data_table @data_table end |
#enable_tooltip ⇒ Object
Chart options accessors
37 38 39 |
# File 'lib/seer/pie_chart.rb', line 37 def enable_tooltip @enable_tooltip end |
#focus_border_color ⇒ Object
Chart options accessors
37 38 39 |
# File 'lib/seer/pie_chart.rb', line 37 def focus_border_color @focus_border_color end |
#height ⇒ Object
Chart options accessors
37 38 39 |
# File 'lib/seer/pie_chart.rb', line 37 def height @height end |
#is_3_d ⇒ Object
:nodoc:
37 38 39 |
# File 'lib/seer/pie_chart.rb', line 37 def is_3_d @is_3_d end |
#label_method ⇒ Object
Graph data
40 41 42 |
# File 'lib/seer/pie_chart.rb', line 40 def label_method @label_method end |
#legend ⇒ Object
Chart options accessors
37 38 39 |
# File 'lib/seer/pie_chart.rb', line 37 def legend @legend end |
#legend_background_color ⇒ Object
Chart options accessors
37 38 39 |
# File 'lib/seer/pie_chart.rb', line 37 def legend_background_color @legend_background_color end |
#legend_font_size ⇒ Object
Chart options accessors
37 38 39 |
# File 'lib/seer/pie_chart.rb', line 37 def legend_font_size @legend_font_size end |
#legend_text_color ⇒ Object
Chart options accessors
37 38 39 |
# File 'lib/seer/pie_chart.rb', line 37 def legend_text_color @legend_text_color end |
#pie_join_angle ⇒ Object
Chart options accessors
37 38 39 |
# File 'lib/seer/pie_chart.rb', line 37 def pie_join_angle @pie_join_angle end |
#pie_minimal_angle ⇒ Object
Chart options accessors
37 38 39 |
# File 'lib/seer/pie_chart.rb', line 37 def pie_minimal_angle @pie_minimal_angle end |
#title ⇒ Object
Chart options accessors
37 38 39 |
# File 'lib/seer/pie_chart.rb', line 37 def title @title end |
#title_color ⇒ Object
Chart options accessors
37 38 39 |
# File 'lib/seer/pie_chart.rb', line 37 def title_color @title_color end |
#title_font_size ⇒ Object
Chart options accessors
37 38 39 |
# File 'lib/seer/pie_chart.rb', line 37 def title_font_size @title_font_size end |
#title_x ⇒ Object
Chart options accessors
37 38 39 |
# File 'lib/seer/pie_chart.rb', line 37 def title_x @title_x end |
#title_y ⇒ Object
Chart options accessors
37 38 39 |
# File 'lib/seer/pie_chart.rb', line 37 def title_y @title_y end |
#tooltip_font_size ⇒ Object
Chart options accessors
37 38 39 |
# File 'lib/seer/pie_chart.rb', line 37 def tooltip_font_size @tooltip_font_size end |
#tooltip_height ⇒ Object
Chart options accessors
37 38 39 |
# File 'lib/seer/pie_chart.rb', line 37 def tooltip_height @tooltip_height end |
#tooltip_width ⇒ Object
Chart options accessors
37 38 39 |
# File 'lib/seer/pie_chart.rb', line 37 def tooltip_width @tooltip_width end |
#width ⇒ Object
Chart options accessors
37 38 39 |
# File 'lib/seer/pie_chart.rb', line 37 def width @width end |
Class Method Details
.render(data, args) ⇒ Object
:nodoc:
103 104 105 106 107 108 109 110 111 112 |
# File 'lib/seer/pie_chart.rb', line 103 def self.render(data, args) #:nodoc: graph = Seer::PieChart.new( :data => data, :label_method => args[:series][:series_label], :data_method => args[:series][:data_method], :chart_options => args[:chart_options], :chart_element => args[:in_element] || 'chart' ) graph.to_js end |
Instance Method Details
#nonstring_options ⇒ Object
:nodoc:
75 76 77 |
# File 'lib/seer/pie_chart.rb', line 75 def #:nodoc: [:colors, :enable_tooltip, :height, :is_3_d, :legend_font_size, :pie_join_angle, :pie_minimal_angle, :title_font_size, :tooltip_font_size, :tooltip_width, :width] end |
#string_options ⇒ Object
:nodoc:
79 80 81 |
# File 'lib/seer/pie_chart.rb', line 79 def #:nodoc: [:background_color, :border_color, :focus_border_color, :legend, :legend_background_color, :legend_text_color, :title, :title_color] end |
#to_js ⇒ Object
:nodoc:
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 |
# File 'lib/seer/pie_chart.rb', line 83 def to_js #:nodoc: %{ <script type="text/javascript"> google.load('visualization', '1', {'packages':['piechart']}); google.setOnLoadCallback(drawChart); function drawChart() { var data = new google.visualization.DataTable(); #{data_columns} #{data_table.join("\r")} var options = {}; #{} var container = document.getElementById('#{self.chart_element}'); var chart = new google.visualization.PieChart(container); chart.draw(data, options); } </script> } end |