Class: QueryReport::Chart::BasicChart
- Inherits:
-
Object
- Object
- QueryReport::Chart::BasicChart
- Defined in:
- lib/query_report/chart/basic_chart.rb
Instance Attribute Summary collapse
-
#columns ⇒ Object
readonly
Returns the value of attribute columns.
-
#data ⇒ Object
readonly
Returns the value of attribute data.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#title ⇒ Object
readonly
Returns the value of attribute title.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Instance Method Summary collapse
-
#initialize(type, name, columns, data, options = {}) ⇒ BasicChart
constructor
A new instance of BasicChart.
- #prepare ⇒ Object
Constructor Details
#initialize(type, name, columns, data, options = {}) ⇒ BasicChart
Returns a new instance of BasicChart.
6 7 8 9 10 11 12 13 14 15 |
# File 'lib/query_report/chart/basic_chart.rb', line 6 def initialize(type, name, columns, data, ={}) @type = type @name = name @columns = [] columns.each_with_index do |column, i| @columns << QueryReport::Column.new(column, {type: (i == 0 ? 'string' : 'number')}) end @data = data = end |
Instance Attribute Details
#columns ⇒ Object (readonly)
Returns the value of attribute columns.
4 5 6 |
# File 'lib/query_report/chart/basic_chart.rb', line 4 def columns @columns end |
#data ⇒ Object (readonly)
Returns the value of attribute data.
4 5 6 |
# File 'lib/query_report/chart/basic_chart.rb', line 4 def data @data end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
4 5 6 |
# File 'lib/query_report/chart/basic_chart.rb', line 4 def end |
#title ⇒ Object (readonly)
Returns the value of attribute title.
4 5 6 |
# File 'lib/query_report/chart/basic_chart.rb', line 4 def title @title end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
4 5 6 |
# File 'lib/query_report/chart/basic_chart.rb', line 4 def type @type end |
Instance Method Details
#prepare ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/query_report/chart/basic_chart.rb', line 17 def prepare data_table = GoogleVisualr::DataTable.new columns.each do |column| data_table.new_column(column.type, column.name) end rows = [] @data.each do |record| row = [] columns.each do |column| row << record[column.name] end rows << row end data_table.add_rows(rows) opts = {:width => 400, :height => 240, :title => title, :hAxis => {:title => columns[0].name}}.merge() chart_type = "#{type}_chart".classify chart_type = "GoogleVisualr::Interactive::#{chart_type}".constantize chart_type.new(data_table, opts) end |