Class: QueryReport::Chart::PieChart
- Inherits:
-
Object
- Object
- QueryReport::Chart::PieChart
- Defined in:
- lib/query_report/chart/pie_chart.rb
Instance Attribute Summary collapse
-
#data_table ⇒ Object
readonly
Returns the value of attribute data_table.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#query ⇒ Object
readonly
Returns the value of attribute query.
-
#rows ⇒ Object
readonly
Returns the value of attribute rows.
-
#title ⇒ Object
readonly
Returns the value of attribute title.
Instance Method Summary collapse
- #add(column_title, &block) ⇒ Object
-
#initialize(title, query, options = {}) ⇒ PieChart
constructor
A new instance of PieChart.
- #prepare ⇒ Object
- #prepare_gruff ⇒ Object
- #to_blob ⇒ Object
Constructor Details
#initialize(title, query, options = {}) ⇒ PieChart
Returns a new instance of PieChart.
8 9 10 11 12 13 |
# File 'lib/query_report/chart/pie_chart.rb', line 8 def initialize(title, query, ={}) @title = title = @rows = [] @query = query end |
Instance Attribute Details
#data_table ⇒ Object (readonly)
Returns the value of attribute data_table.
6 7 8 |
# File 'lib/query_report/chart/pie_chart.rb', line 6 def data_table @data_table end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
6 7 8 |
# File 'lib/query_report/chart/pie_chart.rb', line 6 def end |
#query ⇒ Object (readonly)
Returns the value of attribute query.
6 7 8 |
# File 'lib/query_report/chart/pie_chart.rb', line 6 def query @query end |
#rows ⇒ Object (readonly)
Returns the value of attribute rows.
6 7 8 |
# File 'lib/query_report/chart/pie_chart.rb', line 6 def rows @rows end |
#title ⇒ Object (readonly)
Returns the value of attribute title.
6 7 8 |
# File 'lib/query_report/chart/pie_chart.rb', line 6 def title @title end |
Instance Method Details
#add(column_title, &block) ⇒ Object
15 16 17 18 |
# File 'lib/query_report/chart/pie_chart.rb', line 15 def add(column_title, &block) val = block.call(@query) @rows << [column_title, val] end |
#prepare ⇒ Object
20 21 22 23 24 25 26 27 |
# File 'lib/query_report/chart/pie_chart.rb', line 20 def prepare @data_table = GoogleVisualr::DataTable.new @data_table.new_column('string', 'Item') @data_table.new_column('number', 'Value') @data_table.add_rows(@rows) opts = {:width => 500, :height => 240, :title => @title, :is3D => true, backgroundColor: 'transparent'}.merge() GoogleVisualr::Interactive::PieChart.new(@data_table, opts) end |
#prepare_gruff ⇒ Object
29 30 31 32 33 34 35 36 |
# File 'lib/query_report/chart/pie_chart.rb', line 29 def prepare_gruff @gruff = Gruff::Pie.new([:width] || 600) @gruff.title = title @gruff.theme = Gruff::Themes::GOOGLE_CHART @rows.each do |row| @gruff.data(row[0], row[1]) end end |
#to_blob ⇒ Object
38 39 40 41 |
# File 'lib/query_report/chart/pie_chart.rb', line 38 def to_blob prepare_gruff @gruff.to_blob end |