Class: DynamicReports::Chart
- Inherits:
-
Object
- Object
- DynamicReports::Chart
- Defined in:
- lib/dynamic_reports/charts.rb
Class Method Summary collapse
Instance Method Summary collapse
-
#columns(*array) ⇒ Object
(Optional) Accessor for columns.
-
#height(value = nil) ⇒ Object
(Optional - Default = 175).
-
#initialize(*chart_options) ⇒ Chart
constructor
A new instance of Chart.
-
#label_column(value = nil) ⇒ Object
(Optional) Accessor used by bar and pie charts to determine the independent varible chart labels.
-
#name(value = nil) ⇒ Object
Accessor used to set or get a specific report.
-
#no_labels(value = nil) ⇒ Object
(Optional - Default = false).
- #options ⇒ Object
-
#title(value = nil) ⇒ Object
(Optional) Accessor used to set the chart title:.
-
#type(value = nil) ⇒ Object
(Optional - Default = line).
-
#width(value = nil) ⇒ Object
(Optional - Default = 250).
Constructor Details
#initialize(*chart_options) ⇒ Chart
Returns a new instance of Chart.
13 14 15 16 |
# File 'lib/dynamic_reports/charts.rb', line 13 def initialize(*) = .shift || {} .merge!() end |
Class Method Details
.configure(name, *chart_options, &block) ⇒ Object
5 6 7 8 9 10 11 |
# File 'lib/dynamic_reports/charts.rb', line 5 def self.configure(name, *, &block) = .shift || {} chart = new() chart.instance_eval(&block) chart.name name chart end |
Instance Method Details
#columns(*array) ⇒ Object
(Optional) Accessor for columns
Pass an array of symbols to define columns to chart. Columns MUST be numeric in value to chart.
Example:
columns :pageviews, :visits
You may leave this accessor blank to default to the report columns specified that are numeric.
102 103 104 105 106 107 108 109 110 111 112 |
# File 'lib/dynamic_reports/charts.rb', line 102 def columns(*array) unless array.empty? if (array.class == Array) [:columns] = array else raise "Report columns must be specified." end else [:columns] end end |
#height(value = nil) ⇒ Object
(Optional - Default = 175). Accessor used to set the height, in pixels, of the chart.
height "350"
77 78 79 |
# File 'lib/dynamic_reports/charts.rb', line 77 def height(value = nil) value ? [:height] = value : ([:height] || "175") end |
#label_column(value = nil) ⇒ Object
(Optional) Accessor used by bar and pie charts to determine the independent varible chart labels. Due to size constraints this is NOT used by column or line charts, but you can add labels to the X-axis for those charts via chart_options and passing Google Chart API calls.“
label_column should be a SINGLE column name from the dataset.
label_column "recorded_at"
49 50 51 |
# File 'lib/dynamic_reports/charts.rb', line 49 def label_column(value = nil) value ? [:label_column] = value : [:label_column] end |
#name(value = nil) ⇒ Object
Accessor used to set or get a specific report. Must be unique:
name "PV_Visits"
35 36 37 |
# File 'lib/dynamic_reports/charts.rb', line 35 def name(value = nil) value ? [:name] = value.to_sym : [:name] end |
#no_labels(value = nil) ⇒ Object
(Optional - Default = false). Accessor used to determine if axis labels should be shown. By default y-axis labels are shown.
no_labels true
86 87 88 |
# File 'lib/dynamic_reports/charts.rb', line 86 def no_labels(value = nil) value ? [:no_labels] = value : [:no_labels] end |
#options ⇒ Object
18 19 20 |
# File 'lib/dynamic_reports/charts.rb', line 18 def @options ||= {} ; @options end |
#title(value = nil) ⇒ Object
(Optional) Accessor used to set the chart title:
title "Pageviews versus Visits"
This is displayed above the chart
27 28 29 |
# File 'lib/dynamic_reports/charts.rb', line 27 def title(value = nil) value ? [:title] = value : [:title] end |
#type(value = nil) ⇒ Object
(Optional - Default = line). Accessor used to determine the type of chart to display. Valid options are line, column, bar or pie:
type "bar"
59 60 61 |
# File 'lib/dynamic_reports/charts.rb', line 59 def type(value = nil) value ? [:type] = value : ([:type] || :line) end |
#width(value = nil) ⇒ Object
(Optional - Default = 250). Accessor used to set the width, in pixels, of the chart.
width "400"
68 69 70 |
# File 'lib/dynamic_reports/charts.rb', line 68 def width(value = nil) value ? [:width] = value : ([:width] || "250") end |