Class DynamicReports::Chart

  1. lib/dynamic_reports/charts.rb
Parent: Object

Methods

public class

  1. configure
  2. new

public instance

  1. columns
  2. height
  3. label_column
  4. name
  5. no_labels
  6. options
  7. title
  8. type
  9. width

Public class methods

configure (name, *chart_options, &block)
[show source]
# File lib/dynamic_reports/charts.rb, line 5
    def self.configure(name, *chart_options, &block)
      chart_options = chart_options.shift || {}
      chart = new(chart_options)
      chart.instance_eval(&block)
      chart.name name
      chart
    end
new (*chart_options)
[show source]
# File lib/dynamic_reports/charts.rb, line 13
    def initialize(*chart_options)
      chart_options = chart_options.shift || {}
      options.merge!(chart_options)
    end

Public instance methods

columns (*array)

(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.

[show source]
# File lib/dynamic_reports/charts.rb, line 102
    def columns(*array)
      unless array.empty?
        if (array.class == Array)
          options[:columns] = array
        else
          raise "Report columns must be specified."
        end
      else
        options[:columns]
      end
    end
height (value = nil)

(Optional - Default = 175). Accessor used to set the height, in pixels, of the chart.

height "350"
[show source]
# File lib/dynamic_reports/charts.rb, line 77
    def height(value = nil)
      value ? options[:height] = value : (options[:height] || "175")
    end
label_column (value = nil)

(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"
[show source]
# File lib/dynamic_reports/charts.rb, line 49
    def label_column(value = nil)
      value ? options[:label_column] = value : options[:label_column]
    end
name (value = nil)

Accessor used to set or get a specific report. Must be unique:

name "PV_Visits"
[show source]
# File lib/dynamic_reports/charts.rb, line 35
    def name(value = nil)
      value ? options[:name] = value.to_sym : options[:name]
    end
no_labels (value = nil)

(Optional - Default = false). Accessor used to determine if axis labels should be shown. By default y-axis labels are shown.

no_labels true
[show source]
# File lib/dynamic_reports/charts.rb, line 86
    def no_labels(value = nil)
      value ? options[:no_labels] = value : options[:no_labels]
    end
options ()
[show source]
# File lib/dynamic_reports/charts.rb, line 18
    def options
      @options ||= {} ; @options
    end
title (value = nil)

(Optional) Accessor used to set the chart title:

title "Pageviews versus Visits"

This is displayed above the chart

[show source]
# File lib/dynamic_reports/charts.rb, line 27
    def title(value = nil)
      value ? options[:title] = value : options[:title]
    end
type (value = nil)

(Optional - Default = line). Accessor used to determine the type of chart to display. Valid options are line, column, bar or pie:

type "bar"
[show source]
# File lib/dynamic_reports/charts.rb, line 59
    def type(value = nil)
      value ? options[:type] = value : (options[:type] || :line)
    end
width (value = nil)

(Optional - Default = 250). Accessor used to set the width, in pixels, of the chart.

width "400"
[show source]
# File lib/dynamic_reports/charts.rb, line 68
    def width(value = nil)
      value ? options[:width] = value : (options[:width] || "250")
    end