├── .gitignore ├── CONTRIBUTORS ├── LICENSE ├── README.rdoc ├── Rakefile ├── VERSION ├── init.rb ├── lib ├── seer.rb └── seer │ ├── area_chart.rb │ ├── bar_chart.rb │ ├── chart.rb │ ├── column_chart.rb │ ├── gauge.rb │ ├── geomap.rb │ ├── line_chart.rb │ └── pie_chart.rb ├── rdoc ├── classes │ ├── Seer.html │ └── Seer │ │ ├── AreaChart.html │ │ ├── BarChart.html │ │ ├── ColumnChart.html │ │ ├── Gauge.html │ │ ├── LineChart.html │ │ └── PieChart.html ├── created.rid ├── files │ ├── README_rdoc.html │ └── lib │ │ ├── seer │ │ ├── area_chart_rb.html │ │ ├── bar_chart_rb.html │ │ ├── chart_rb.html │ │ ├── column_chart_rb.html │ │ ├── gauge_rb.html │ │ ├── line_chart_rb.html │ │ └── pie_chart_rb.html │ │ └── seer_rb.html ├── fr_class_index.html ├── fr_file_index.html ├── fr_method_index.html ├── index.html └── rdoc-style.css ├── seer.gemspec └── spec ├── area_chart_spec.rb ├── bar_chart_spec.rb ├── chart_spec.rb ├── column_chart_spec.rb ├── custom_matchers.rb ├── gauge_spec.rb ├── geomap_spec.rb ├── helpers.rb ├── line_chart_spec.rb ├── pie_chart_spec.rb ├── seer_spec.rb ├── spec.opts └── spec_helper.rb /.gitignore: -------------------------------------------------------------------------------- 1 | pkg 2 | doc 3 | Manifest -------------------------------------------------------------------------------- /CONTRIBUTORS: -------------------------------------------------------------------------------- 1 | Thanks go to the following individuals for their contributions: 2 | 3 | Alexey Kuleshov (http://github.com/kulesa) 4 | Harold Giménez (http://github.com/hgimenez) 5 | Henry Poydar (http://github.com/hpoydar) 6 | 7 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2010 Corey Ehmke / SEO Logic 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining 4 | a copy of this software and associated documentation files (the 5 | "Software"), to deal in the Software without restriction, including 6 | without limitation the rights to use, copy, modify, merge, publish, 7 | distribute, sublicense, and/or sell copies of the Software, and to 8 | permit persons to whom the Software is furnished to do so, subject to 9 | the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be 12 | included in all copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 15 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 17 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 18 | LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 19 | OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 20 | WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | -------------------------------------------------------------------------------- /README.rdoc: -------------------------------------------------------------------------------- 1 | =Seer 2 | 3 | Seer is a lightweight, semantically rich wrapper for the Google Visualization API. It allows you to easily create a visualization of data in a variety of formats, including area charts, bar charts, column charts, gauges, line charts, and pie charts. 4 | 5 | ==Usage 6 | 7 | Add the following to the head of the page that will display a chart, or add it to your layout file: 8 | 9 | <%= Seer::init_visualization -%> 10 | 11 | Gather the data you want to visualize in an instance variable in your controller, then use the visualize method to insert the appropriate chart in your view. 12 | 13 | == Example 14 | 15 | In your controller: 16 | 17 | # @data must be an array, and each object in the array must respond to the data method specified 18 | # in the visualize call (in this example, 'quantity') 19 | @data = Widget.all 20 | 21 | In your view: 22 | 23 |
24 | 25 | <%= Seer::visualize( 26 | @widgets, 27 | :as => :bar_chart, 28 | :in_element => 'chart', 29 | :series => {:series_label => 'name', :data_method => 'quantity'}, 30 | :chart_options => { 31 | :height => 300, 32 | :width => 200 * @widgets.size, 33 | :is_3_d => false, 34 | :legend => 'none', 35 | :colors => ["#990000"], 36 | :title => "Widget Quantities", 37 | :title_x => 'Quantity', 38 | :title_y => 'Widgets' 39 | } 40 | ) 41 | -%> 42 | 43 | == More information 44 | 45 | For examples of additional chart types, refer to the documentation for each of the individual chart objects, or see the blog post announcing Seer: {Simple, Semantic Graphing for Ruby on Rails with Seer}[http://www.idolhands.com/ruby-on-rails/gems-plugins-and-engines/graphing-for-ruby-on-rails-with-seer] 46 | 47 | A {sample project}[http://github.com/Bantik/seer_sample] that demonstrates each of the chart types is available on GitHub. 48 | 49 | Seer is developed and maintained by {Corey Ehmke}[http://www.idolhands.com/] at {SEO Logic}[http://www.seologic.com/]. 50 | 51 | Copyright (c) 2010 Corey Ehmke / SEO Logic, released under the MIT license 52 | -------------------------------------------------------------------------------- /Rakefile: -------------------------------------------------------------------------------- 1 | require 'rubygems' 2 | require 'rake' 3 | 4 | begin 5 | require 'jeweler' 6 | Jeweler::Tasks.new do |gem| 7 | gem.name = "seer" 8 | gem.summary = %Q{Seer is a lightweight, semantically rich wrapper for the Google Visualization API.} 9 | gem.description = %Q{ Seer is a lightweight, semantically rich wrapper for the Google Visualization API. It allows you to easily create a visualization of data in a variety of formats, including area charts, bar charts, column charts, gauges, line charts, and pie charts.} 10 | gem.email = "corey@seologic.com" 11 | gem.homepage = "http://github.com/Bantik/seer" 12 | gem.authors = ["Corey Ehmke / SEO Logic"] 13 | gem.add_development_dependency "rspec", ">= 1.2.9" 14 | gem.files = [ 15 | "CONTRIBUTORS", 16 | "init.rb", 17 | "lib/seer.rb", 18 | "lib/seer/area_chart.rb", 19 | "lib/seer/bar_chart.rb", 20 | "lib/seer/chart.rb", 21 | "lib/seer/column_chart.rb", 22 | "lib/seer/gauge.rb", 23 | "lib/seer/geomap.rb", 24 | "lib/seer/line_chart.rb", 25 | "lib/seer/pie_chart.rb", 26 | "lib/seer/visualization_helper.rb", 27 | "LICENSE", 28 | "Rakefile", 29 | "README.rdoc", 30 | "rails/init.rb", 31 | "spec/spec.opts", 32 | "spec/spec_helper.rb", 33 | "spec/seer_spec.rb" 34 | ] 35 | end 36 | Jeweler::GemcutterTasks.new 37 | rescue LoadError 38 | puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler" 39 | end 40 | 41 | require 'rake/rdoctask' 42 | Rake::RDocTask.new do |rdoc| 43 | version = File.exist?('VERSION') ? File.read('VERSION') : "" 44 | 45 | rdoc.rdoc_dir = 'rdoc' 46 | rdoc.title = "seer #{version}" 47 | rdoc.rdoc_files.include('README*') 48 | rdoc.rdoc_files.include('lib/**/*.rb') 49 | end 50 | -------------------------------------------------------------------------------- /VERSION: -------------------------------------------------------------------------------- 1 | 0.10.0 -------------------------------------------------------------------------------- /init.rb: -------------------------------------------------------------------------------- 1 | require 'seer' 2 | -------------------------------------------------------------------------------- /lib/seer.rb: -------------------------------------------------------------------------------- 1 | module Seer 2 | 3 | require 'seer/chart' 4 | require 'seer/area_chart' 5 | require 'seer/bar_chart' 6 | require 'seer/column_chart' 7 | require 'seer/gauge' 8 | require 'seer/geomap' 9 | require 'seer/line_chart' 10 | require 'seer/pie_chart' 11 | 12 | VISUALIZERS = [:area_chart, :bar_chart, :column_chart, :gauge, :geomap, :line_chart, :pie_chart] 13 | 14 | def self.valid_hex_number?(val) #:nodoc: 15 | return false unless val.is_a?(String) && ! val.empty? 16 | ! (val =~ /^\#([0-9]|[a-f]|[A-F])+$/).nil? && val.length == 7 17 | end 18 | 19 | def self.log(message) #:nodoc: 20 | RAILS_DEFAULT_LOGGER.info(message) 21 | end 22 | 23 | def self.init_visualization 24 | %{ 25 | 29 | } 30 | end 31 | 32 | def self.visualize(data, args={}) 33 | raise ArgumentError, "Seer: Invalid visualizer: #{args[:as]}" unless args[:as] && VISUALIZERS.include?(args[:as]) 34 | raise ArgumentError, "Seer: No data provided!" unless data && ! data.empty? 35 | self.send(args[:as], data, args) 36 | end 37 | 38 | private 39 | 40 | def self.area_chart(data, args) 41 | AreaChart.render(data, args) 42 | end 43 | 44 | def self.bar_chart(data, args) 45 | BarChart.render(data, args) 46 | end 47 | 48 | def self.column_chart(data, args) 49 | ColumnChart.render(data, args) 50 | end 51 | 52 | def self.gauge(data, args) 53 | Gauge.render(data, args) 54 | end 55 | 56 | def self.geomap(data, args) 57 | Geomap.render(data, args) 58 | end 59 | 60 | def self.line_chart(data, args) 61 | LineChart.render(data, args) 62 | end 63 | 64 | def self.pie_chart(data, args) 65 | PieChart.render(data, args) 66 | end 67 | 68 | end 69 | -------------------------------------------------------------------------------- /lib/seer/area_chart.rb: -------------------------------------------------------------------------------- 1 | module Seer 2 | 3 | # =USAGE 4 | # 5 | # In your controller: 6 | # 7 | # @data = Widgets.all # Must be an array, and must respond 8 | # # to the data method specified below (in this example, 'quantity') 9 | # 10 | # @series = @data.map{|w| w.widget_stats} # An array of arrays 11 | # 12 | # In your view: 13 | # 14 | # 15 | # 16 | # <%= Seer::visualize( 17 | # @data, 18 | # :as => :area_chart, 19 | # :in_element => 'chart', 20 | # :series => { 21 | # :series_label => 'name', 22 | # :data_label => 'date', 23 | # :data_method => 'quantity', 24 | # :data_series => @series 25 | # }, 26 | # :chart_options => { 27 | # :height => 300, 28 | # :width => 300, 29 | # :axis_font_size => 11, 30 | # :colors => ['#7e7587','#990000','#009900'], 31 | # :title => "Widget Quantities", 32 | # :point_size => 5 33 | # } 34 | # ) 35 | # -%> 36 | # 37 | # For details on the chart options, see the Google API docs at 38 | # http://code.google.com/apis/visualization/documentation/gallery/areachart.html 39 | # 40 | class AreaChart 41 | 42 | include Seer::Chart 43 | 44 | # Graph options 45 | attr_accessor :axis_color, :axis_background_color, :axis_font_size, :background_color, :border_color, :data_table, :enable_tooltip, :focus_border_color, :height, :is_stacked, :legend, :legend_background_color, :legend_font_size, :legend_text_color, :line_size, :log_scale, :max, :min, :point_size, :reverse_axis, :show_categories, :title, :title_x, :title_y, :title_color, :title_font_size, :tooltip_font_size, :tooltip_height, :number, :tooltip_width, :width 46 | 47 | # Graph data 48 | attr_accessor :series_label, :data_label, :data, :data_method, :data_series 49 | 50 | def initialize(args={}) #:nodoc: 51 | 52 | # Standard options 53 | args.each{ |method,arg| self.send("#{method}=",arg) if self.respond_to?(method) } 54 | 55 | # Chart options 56 | args[:chart_options].each{ |method, arg| self.send("#{method}=",arg) if self.respond_to?(method) } 57 | 58 | # Handle defaults 59 | @colors ||= args[:chart_options][:colors] || DEFAULT_COLORS 60 | @legend ||= args[:chart_options][:legend] || DEFAULT_LEGEND_LOCATION 61 | @height ||= args[:chart_options][:height] || DEFAULT_HEIGHT 62 | @width ||= args[:chart_options][:width] || DEFAULT_WIDTH 63 | 64 | @data_table = [] 65 | 66 | end 67 | 68 | def data_columns #:nodoc: 69 | _data_columns = " data.addRows(#{data_rows.size});\r" 70 | _data_columns << " data.addColumn('string', 'Date');\r" 71 | data.each do |datum| 72 | _data_columns << " data.addColumn('number', '#{datum.send(series_label)}');\r" 73 | end 74 | _data_columns 75 | end 76 | 77 | def data_table #:nodoc: 78 | _rows = data_rows 79 | _rows.each_with_index do |r,i| 80 | @data_table << " data.setCell(#{i}, 0,'#{r}');\r" 81 | end 82 | data_series.each_with_index do |column,i| 83 | column.each_with_index do |c,j| 84 | @data_table << " data.setCell(#{j},#{i+1},#{c.send(data_method)});\r" 85 | end 86 | end 87 | @data_table 88 | end 89 | 90 | def data_rows 91 | data_series.inject([]) do |rows, element| 92 | rows |= element.map { |e| e.send(data_label) } 93 | end 94 | end 95 | 96 | def nonstring_options #:nodoc: 97 | [ :axis_font_size, :colors, :enable_tooltip, :height, :is_stacked, :legend_font_size, :line_size, :log_scale, :max, :min, :point_size, :reverse_axis, :show_categories, :title_font_size, :tooltip_font_size, :tooltip_height, :tooltip_width, :width] 98 | end 99 | 100 | def string_options #:nodoc: 101 | [ :axis_color, :axis_background_color, :background_color, :border_color, :focus_border_color, :legend, :legend_background_color, :legend_text_color, :title, :title_x, :title_y, :title_color ] 102 | end 103 | 104 | def to_js #:nodoc: 105 | 106 | %{ 107 | 121 | } 122 | end 123 | 124 | def self.render(data, args) #:nodoc: 125 | graph = Seer::AreaChart.new( 126 | :data => data, 127 | :series_label => args[:series][:series_label], 128 | :data_series => args[:series][:data_series], 129 | :data_label => args[:series][:data_label], 130 | :data_method => args[:series][:data_method], 131 | :chart_options => args[:chart_options], 132 | :chart_element => args[:in_element] || 'chart' 133 | ) 134 | graph.to_js 135 | end 136 | 137 | end 138 | 139 | end 140 | -------------------------------------------------------------------------------- /lib/seer/bar_chart.rb: -------------------------------------------------------------------------------- 1 | module Seer 2 | 3 | # =USAGE 4 | # 5 | # In your controller: 6 | # 7 | # @data = Widgets.all # Must be an array, and must respond 8 | # # to the data method specified below (in this example, 'quantity') 9 | # 10 | # In your view: 11 | # 12 | # 13 | # 14 | # <%= Seer::visualize( 15 | # @widgets, 16 | # :as => :bar_chart, 17 | # :in_element => 'chart', 18 | # :series => {:series_label => 'name', :data_method => 'quantity'}, 19 | # :chart_options => { 20 | # :height => 300, 21 | # :width => 200 * @widgets.size, 22 | # :is_3_d => false, 23 | # :legend => 'none', 24 | # :colors => ["#990000"], 25 | # :title => "Widget Quantities", 26 | # :title_x => 'Quantity', 27 | # :title_y => 'Widgets' 28 | # } 29 | # ) 30 | # -%> 31 | # 32 | # Colors are treated differently for 2d and 3d graphs. If you set is_3_d to true, set the 33 | # graph colors like this: 34 | # 35 | # :colors => "[{color:'#990000', darker:'#660000'}]", 36 | # 37 | # For details on the chart options, see the Google API docs at 38 | # http://code.google.com/apis/visualization/documentation/gallery/barchart.html 39 | # 40 | class BarChart 41 | 42 | include Seer::Chart 43 | 44 | # Chart options accessors 45 | attr_accessor :axis_color, :axis_background_color, :axis_font_size, :background_color, :border_color, :data_table, :enable_tooltip, :focus_border_color, :font_size, :height, :is_3_d, :is_stacked, :legend, :legend_background_color, :legend_font_size, :legend_text_color, :log_scale, :max, :min, :reverse_axis, :show_categories, :title, :title_x, :title_y, :title_color, :title_font_size, :tooltip_font_size, :tooltip_height, :tooltip_width, :width 46 | 47 | # Graph data 48 | attr_accessor :data, :data_method, :label_method 49 | 50 | def initialize(args={}) #:nodoc: 51 | 52 | # Standard options 53 | args.each{ |method,arg| self.send("#{method}=",arg) if self.respond_to?(method) } 54 | 55 | # Chart options 56 | args[:chart_options].each{ |method, arg| self.send("#{method}=",arg) if self.respond_to?(method) } 57 | 58 | # Handle defaults 59 | @colors ||= args[:chart_options][:colors] || DEFAULT_COLORS 60 | @legend ||= args[:chart_options][:legend] || DEFAULT_LEGEND_LOCATION 61 | @height ||= args[:chart_options][:height] || DEFAULT_HEIGHT 62 | @width ||= args[:chart_options][:width] || DEFAULT_WIDTH 63 | @is_3_d ||= args[:chart_options][:is_3_d] 64 | 65 | @data_table = [] 66 | 67 | end 68 | 69 | def data_table #:nodoc: 70 | data.each_with_index do |datum, column| 71 | @data_table << [ 72 | " data.setValue(#{column}, 0,'#{datum.send(label_method)}');\r", 73 | " data.setValue(#{column}, 1, #{datum.send(data_method)});\r" 74 | ] 75 | end 76 | @data_table 77 | end 78 | 79 | def is_3_d #:nodoc: 80 | @is_3_d.blank? ? false : @is_3_d 81 | end 82 | 83 | def nonstring_options #:nodoc: 84 | [:axis_font_size, :colors, :enable_tooltip, :is_3_d, :is_stacked, :legend_font_size, :log_scale, :max, :min, :reverse_axis, :show_categories, :title_font_size, :tooltip_font_size, :tooltip_width] 85 | end 86 | 87 | def string_options #:nodoc: 88 | [:axis_color, :axis_background_color, :background_color, :border_color, :focus_border_color, :height, :legend, :legend_background_color, :legend_text_color, :title, :title_x, :title_y, :title_color, :width] 89 | end 90 | 91 | def to_js #:nodoc: 92 | 93 | %{ 94 | 108 | } 109 | end 110 | 111 | def self.render(data, args) #:nodoc: 112 | graph = Seer::BarChart.new( 113 | :label_method => args[:series][:series_label], 114 | :data_method => args[:series][:data_method], 115 | :chart_options => args[:chart_options], 116 | :chart_element => args[:in_element] || 'chart', 117 | :data => data 118 | ) 119 | graph.to_js 120 | end 121 | 122 | end 123 | 124 | end 125 | -------------------------------------------------------------------------------- /lib/seer/chart.rb: -------------------------------------------------------------------------------- 1 | module Seer 2 | 3 | module Chart #:nodoc: 4 | 5 | attr_accessor :chart_element, :colors 6 | 7 | DEFAULT_COLORS = ['#324F69','#919E4B', '#A34D4D', '#BEC8BE'] 8 | DEFAULT_LEGEND_LOCATION = 'bottom' 9 | DEFAULT_HEIGHT = 350 10 | DEFAULT_WIDTH = 550 11 | 12 | def in_element=(elem) 13 | @chart_element = elem 14 | end 15 | 16 | def colors=(colors_list) 17 | unless colors_list.include?('darker') 18 | raise ArgumentError, "Invalid color option: #{colors_list}" unless colors_list.is_a?(Array) 19 | colors_list.each do |color| 20 | raise ArgumentError, "Invalid color option: #{colors_list}" unless Seer.valid_hex_number?(color) 21 | end 22 | end 23 | @colors = colors_list 24 | end 25 | 26 | def formatted_colors 27 | if @colors.include?('darker') 28 | @colors 29 | else 30 | "[#{@colors.map{|color| "'#{color.gsub(/\#/,'')}'"} * ','}]" 31 | end 32 | end 33 | 34 | def data_columns 35 | _data_columns = " data.addRows(#{data_table.size});\r" 36 | _data_columns << " data.addColumn('string', '#{label_method}');\r" 37 | _data_columns << " data.addColumn('number', '#{data_method}');\r" 38 | _data_columns 39 | end 40 | 41 | def options 42 | _options = "" 43 | nonstring_options.each do |opt| 44 | next unless self.send(opt) 45 | if opt == :colors 46 | _options << " options['#{opt.to_s.camelize(:lower)}'] = #{self.send(:formatted_colors)};\r" 47 | else 48 | _options << " options['#{opt.to_s.camelize(:lower)}'] = #{self.send(opt)};\r" 49 | end 50 | end 51 | string_options.each do |opt| 52 | next unless self.send(opt) 53 | _options << " options['#{opt.to_s.camelize(:lower)}'] = '#{self.send(opt)}';\r" 54 | end 55 | _options 56 | end 57 | 58 | end 59 | 60 | end -------------------------------------------------------------------------------- /lib/seer/column_chart.rb: -------------------------------------------------------------------------------- 1 | module Seer 2 | 3 | # =USAGE 4 | # 5 | # In your controller: 6 | # 7 | # @data = Widgets.all # Must be an array, and must respond 8 | # # to the data method specified below (in this example, 'quantity') 9 | # 10 | # In your view: 11 | # 12 | # 13 | # 14 | # <%= Seer::visualize( 15 | # @widgets, 16 | # :as => :column_chart, 17 | # :in_element => 'chart', 18 | # :series => {:series_label => 'name', :data_method => 'quantity'}, 19 | # :chart_options => { 20 | # :height => 300, 21 | # :width => 300, 22 | # :is_3_d => true, 23 | # :legend => 'none', 24 | # :colors => "[{color:'#990000', darker:'#660000'}]", 25 | # :title => "Widget Quantities", 26 | # :title_x => 'Widgets', 27 | # :title_y => 'Quantities' 28 | # } 29 | # ) 30 | # -%> 31 | # 32 | # Colors are treated differently for 2d and 3d graphs. If you set is_3_d to false, set the 33 | # graph color like this: 34 | # 35 | # :colors => "#990000" 36 | # 37 | # For details on the chart options, see the Google API docs at 38 | # http://code.google.com/apis/visualization/documentation/gallery/columnchart.html 39 | # 40 | class ColumnChart 41 | 42 | include Seer::Chart 43 | 44 | # Chart options accessors 45 | attr_accessor :axis_color, :axis_background_color, :axis_font_size, :background_color, :border_color, :enable_tooltip, :focus_border_color, :height, :is_3_d, :is_stacked, :legend, :legend_background_color, :legend_font_size, :legend_text_color, :log_scale, :max, :min, :reverse_axis, :show_categories, :title, :title_x, :title_y, :title_color, :title_font_size, :tooltip_font_size, :tooltip_height, :tooltip_width, :width 46 | 47 | # Graph data 48 | attr_accessor :data, :data_method, :data_table, :label_method 49 | 50 | def initialize(args={}) #:nodoc: 51 | 52 | # Standard options 53 | args.each{ |method,arg| self.send("#{method}=",arg) if self.respond_to?(method) } 54 | 55 | # Chart options 56 | args[:chart_options].each{ |method, arg| self.send("#{method}=",arg) if self.respond_to?(method) } 57 | 58 | # Handle defaults 59 | @colors ||= args[:chart_options][:colors] || DEFAULT_COLORS 60 | @legend ||= args[:chart_options][:legend] || DEFAULT_LEGEND_LOCATION 61 | @height ||= args[:chart_options][:height] || DEFAULT_HEIGHT 62 | @width ||= args[:chart_options][:width] || DEFAULT_WIDTH 63 | @is_3_d ||= args[:chart_options][:is_3_d] 64 | 65 | @data_table = [] 66 | 67 | end 68 | 69 | def data_table #:nodoc: 70 | data.each_with_index do |datum, column| 71 | @data_table << [ 72 | " data.setValue(#{column}, 0,'#{datum.send(label_method)}');\r", 73 | " data.setValue(#{column}, 1, #{datum.send(data_method)});\r" 74 | ] 75 | end 76 | @data_table 77 | end 78 | 79 | def is_3_d #:nodoc: 80 | @is_3_d.blank? ? false : @is_3_d 81 | end 82 | 83 | def nonstring_options #:nodoc: 84 | [:axis_font_size, :colors, :enable_tooltip, :height, :is_3_d, :is_stacked, :legend_font_size, :log_scale, :max, :min, :reverse_axis, :show_categories, :title_font_size, :tooltip_font_size, :tooltip_width, :width] 85 | end 86 | 87 | def string_options #:nodoc: 88 | [:axis_color, :axis_background_color, :background_color, :border_color, :focus_border_color, :legend, :legend_background_color, :legend_text_color, :title, :title_x, :title_y, :title_color] 89 | end 90 | 91 | def to_js #:nodoc: 92 | 93 | %{ 94 | 108 | } 109 | end 110 | 111 | def self.render(data, args) #:nodoc: 112 | graph = Seer::ColumnChart.new( 113 | :data => data, 114 | :label_method => args[:series][:series_label], 115 | :data_method => args[:series][:data_method], 116 | :chart_options => args[:chart_options], 117 | :chart_element => args[:in_element] || 'chart' 118 | ) 119 | graph.to_js 120 | end 121 | 122 | end 123 | 124 | end 125 | -------------------------------------------------------------------------------- /lib/seer/gauge.rb: -------------------------------------------------------------------------------- 1 | module Seer 2 | 3 | # =USAGE 4 | # 5 | # In your controller: 6 | # 7 | # @data = Widgets.all # Must be an array, and must respond 8 | # # to the data method specified below (in this example, 'quantity') 9 | # 10 | # In your view: 11 | # 12 | # 13 | # 14 | # <%= Seer::visualize( 15 | # @data, 16 | # :as => :gauge, 17 | # :in_element => 'chart', 18 | # :series => {:series_label => 'name', :data_method => 'quantity'}, 19 | # :chart_options => { 20 | # :green_from => 0, 21 | # :green_to => 50, 22 | # :height => 300, 23 | # :max => 100, 24 | # :min => 0, 25 | # :minor_ticks => 5, 26 | # :red_from => 76, 27 | # :red_to => 100, 28 | # :width => 600, 29 | # :yellow_from => 51, 30 | # :yellow_to => 75 31 | # } 32 | # ) 33 | # -%> 34 | # 35 | # For details on the chart options, see the Google API docs at 36 | # http://code.google.com/apis/visualization/documentation/gallery/gauge.html 37 | # 38 | class Gauge 39 | 40 | include Seer::Chart 41 | 42 | # Chart options accessors 43 | attr_accessor :green_from, :green_to, :height, :major_ticks, :max, :min, :minor_ticks, :red_from, :red_to, :width, :yellow_from, :yellow_to 44 | 45 | # Graph data 46 | attr_accessor :data, :data_method, :data_table, :label_method 47 | 48 | def initialize(args={}) #:nodoc: 49 | 50 | # Standard options 51 | args.each{ |method,arg| self.send("#{method}=",arg) if self.respond_to?(method) } 52 | 53 | # Chart options 54 | args[:chart_options].each{ |method, arg| self.send("#{method}=",arg) if self.respond_to?(method) } 55 | 56 | # Handle defaults 57 | @height ||= args[:chart_options][:height] || DEFAULT_HEIGHT 58 | @width ||= args[:chart_options][:width] || DEFAULT_WIDTH 59 | 60 | @data_table = [] 61 | 62 | end 63 | 64 | def data_table #:nodoc: 65 | data.each_with_index do |datum, column| 66 | @data_table << [ 67 | " data.setValue(#{column}, 0,'#{datum.send(label_method)}');\r", 68 | " data.setValue(#{column}, 1, #{datum.send(data_method)});\r" 69 | ] 70 | end 71 | @data_table 72 | end 73 | 74 | def is_3_d #:nodoc: 75 | @is_3_d.blank? ? false : @is_3_d 76 | end 77 | 78 | def nonstring_options #:nodoc: 79 | [:green_from, :green_to, :height, :major_ticks, :max, :min, :minor_ticks, :red_from, :red_to, :width, :yellow_from, :yellow_to] 80 | end 81 | 82 | def string_options #:nodoc: 83 | [] 84 | end 85 | 86 | def to_js #:nodoc: 87 | 88 | %{ 89 | 103 | } 104 | end 105 | 106 | def self.render(data, args) #:nodoc: 107 | graph = Seer::Gauge.new( 108 | :data => data, 109 | :label_method => args[:series][:series_label], 110 | :data_method => args[:series][:data_method], 111 | :chart_options => args[:chart_options], 112 | :chart_element => args[:in_element] || 'chart' 113 | ) 114 | graph.to_js 115 | end 116 | 117 | end 118 | 119 | end 120 | -------------------------------------------------------------------------------- /lib/seer/geomap.rb: -------------------------------------------------------------------------------- 1 | module Seer 2 | 3 | # Geomap creates a map of a country, continent, or region, with colors and values assigned to 4 | # specific regions. Values are displayed as a color scale, and you can specify optional hovertext 5 | # for regions. 6 | # 7 | # =USAGE= 8 | # 9 | # In your view: 10 | # 11 | # 12 | # 13 | # <%= Seer::visualize( 14 | # @locations, 15 | # :as => :geomap, 16 | # :in_element => 'my_geomap_container', 17 | # :series => { 18 | # :series_label => 'name', 19 | # :data_label => '# widgets', 20 | # :data_method => 'widget_count' 21 | # }, 22 | # :chart_options => { 23 | # :data_mode => 'regions', 24 | # :region => 'US', 25 | # } 26 | # ) 27 | # -%> 28 | # 29 | # ==@locations== 30 | # 31 | # A collection of objects (ActiveRecord or otherwise) that must respond to the 32 | # following methods: 33 | # 34 | # latitude # => returns the latitude in decimal format 35 | # longitude # => returns the longitude in decimal format 36 | # geocoded? # => result of latitude && longitude 37 | # 38 | # For details on the chart options, see the Google API docs at 39 | # http://code.google.com/apis/visualization/documentation/gallery/geomap.html 40 | # 41 | class Geomap 42 | 43 | include Seer::Chart 44 | 45 | COUNTRY_CODES = ['world', 'AX', 'AF', 'AL', 'DZ', 'AS', 'AD', 'AO', 'AI', 'AQ', 'AG', 'AR', 'AM', 'AW', 'AU', 'AT', 'AZ', 'BS', 'BH', 'BD', 'BB', 'BY', 'BE', 'BZ', 'BJ', 'BM', 'BT', 'BO', 'BA', 'BW', 'BV', 'BR', 'IO', 'BN', 'BG', 'BF', 'BI', 'KH', 'CM', 'CA', 'CV', 'KY', 'CF', 'TD', 'CL', 'CN', 'CX', 'CC', 'CO', 'KM', 'CD', 'CG', 'CK', 'CR', 'CI', 'HR', 'CU', 'CY', 'CZ', 'DK', 'DJ', 'DM', 'DO', 'EC', 'EG', 'SV', 'GQ', 'ER', 'EE', 'ET', 'FK', 'FO', 'FJ', 'FI', 'FR', 'GF', 'PF', 'TF', 'GA', 'GM', 'GE', 'DE', 'GH', 'GI', 'GR', 'GL', 'GD', 'GP', 'GU', 'GT', 'GN', 'GW', 'GY', 'HT', 'HM', 'HN', 'HK', 'HU', 'IS', 'IN', 'ID', 'IR', 'IQ', 'IE', 'IL', 'IT', 'JM', 'JP', 'JO', 'KZ', 'KE', 'KI', 'KP', 'KR', 'KW', 'KG', 'LA', 'LV', 'LB', 'LS', 'LR', 'LY', 'LI', 'LT', 'LU', 'MO', 'MK', 'MG', 'MW', 'MY', 'MV', 'ML', 'MT', 'MH', 'MQ', 'MR', 'MU', 'YT', 'MX', 'FM', 'MD', 'MC', 'MN', 'MS', 'MA', 'MZ', 'MM', 'NA', 'NR', 'NP', 'NL', 'AN', 'NC', 'NZ', 'NI', 'NE', 'NG', 'NU', 'NF', 'MP', 'NO', 'OM', 'PK', 'PW', 'PS', 'PA', 'PG', 'PY', 'PE', 'PH', 'PN', 'PL', 'PT', 'PR', 'QA', 'RE', 'RO', 'RU', 'RW', 'SH', 'KN', 'LC', 'PM', 'VC', 'WS', 'SM', 'ST', 'SA', 'SN', 'CS', 'SC', 'SL', 'SG', 'SK', 'SI', 'SB', 'SO', 'ZA', 'GS', 'ES', 'LK', 'SD', 'SR', 'SJ', 'SZ', 'SE', 'CH', 'SY', 'TW', 'TJ', 'TZ', 'TH', 'TL', 'TG', 'TK', 'TO', 'TT', 'TN', 'TR', 'TM', 'TC', 'TV', 'UG', 'UA', 'AE', 'GB', 'US', 'us_metro', 'UM', 'UY', 'UZ', 'VU', 'VA', 'VE', 'VN', 'VG', 'VI', 'WF', 'EH', 'YE', 'ZM', 'ZW', '005', '013', '021', '002', '017', '015', '018', '030', '034', '035', '143', '145', '151', '154', '155', '039'] 46 | 47 | # Chart options accessors 48 | attr_accessor :data_mode, :enable_tooltip, :height, :legend_background_color, :legend_font_size, :legend_text_color, :legend, :region, :show_legend, :show_zoom_out, :title_color, :title_font_size, :title_x, :title_y, :title, :tooltip_font_size, :tooltip_height, :tooltip_width, :width, :zoom_out_label 49 | 50 | # Graph data 51 | attr_accessor :data, :data_label, :data_method, :data_table, :label_method 52 | 53 | def initialize(args={}) #:nodoc: 54 | 55 | # Standard options 56 | args.each{ |method,arg| self.send("#{method}=",arg) if self.respond_to?(method) } 57 | 58 | # Chart options 59 | args[:chart_options].each{ |method, arg| self.send("#{method}=",arg) if self.respond_to?(method) } 60 | 61 | # Handle defaults 62 | @colors ||= args[:chart_options][:colors] || DEFAULT_COLORS 63 | @legend ||= args[:chart_options][:legend] || DEFAULT_LEGEND_LOCATION 64 | @height ||= args[:chart_options][:height] || DEFAULT_HEIGHT 65 | @width ||= args[:chart_options][:width] || DEFAULT_WIDTH 66 | 67 | end 68 | 69 | def data_columns #:nodoc: 70 | _data_columns = "data.addRows(#{data_table.size});" 71 | if self.data_mode == 'markers' 72 | _data_columns << %{ 73 | data.addColumn('number', 'LATITUDE'); 74 | data.addColumn('number', 'LONGITUDE'); 75 | data.addColumn('number', '#{data_method}'); 76 | data.addColumn('string', '#{label_method}'); 77 | } 78 | else 79 | _data_columns << " data.addColumn('string', '#{label_method}');" 80 | _data_columns << " data.addColumn('number', '#{data_method}');" 81 | _data_columns 82 | end 83 | _data_columns 84 | end 85 | 86 | def data_mode=(mode) #:nodoc: 87 | raise ArgumentError, "Invalid data mode option: #{mode}. Must be one of 'regions' or 'markers'." unless ['regions', 'markers'].include?(mode) 88 | @data_mode = mode 89 | end 90 | 91 | def data_table #:nodoc: 92 | @data_table = [] 93 | data.select{ |d| d.geocoded? }.each_with_index do |datum, column| 94 | if data_mode == "markers" 95 | @data_table << [ 96 | " data.setValue(#{column}, 0, #{datum.latitude});\r", 97 | " data.setValue(#{column}, 1, #{datum.longitude});\r", 98 | " data.setValue(#{column}, 2, #{datum.send(data_method)});\r", 99 | " data.setValue(#{column}, 3, '#{datum.send(label_method)}');\r" 100 | ] 101 | else # Regions 102 | @data_table << [ 103 | " data.setValue(#{column}, 0, '#{datum.name}');\r", 104 | " data.setValue(#{column}, 1, #{datum.send(data_method)});\r" 105 | ] 106 | end 107 | end 108 | @data_table 109 | end 110 | 111 | # Because Google is not consistent in their @#!$ API... 112 | def formatted_colors 113 | "[#{@colors.map{|color| "'#{color.gsub(/\#/,'0x')}'"} * ','}]" 114 | end 115 | 116 | def nonstring_options #:nodoc: 117 | [:colors, :enable_tooltip, :height, :legend_font_size, :title_font_size, :tooltip_font_size, :tooltip_width, :width] 118 | end 119 | 120 | def string_options #:nodoc: 121 | [:data_mode, :legend, :legend_background_color, :legend_text_color, :title, :title_x, :title_y, :title_color, :region] 122 | end 123 | 124 | def to_js 125 | %{ 126 | 140 | } 141 | end 142 | 143 | def region=(desired_region) 144 | raise ArgumentError, "Invalid region: #{desired_region}" unless COUNTRY_CODES.include?(desired_region) 145 | @region = desired_region 146 | end 147 | 148 | # ====================================== Class Methods ========================================= 149 | 150 | def self.render(data, args) 151 | map = Seer::Geomap.new( 152 | :region => args[:chart_options][:region], 153 | :data_mode => args[:chart_options][:data_mode], 154 | :data => data, 155 | :label_method => args[:series][:series_label], 156 | :data_method => args[:series][:data_method], 157 | :chart_options => args[:chart_options], 158 | :chart_element => args[:in_element] || 'chart' 159 | ) 160 | map.to_js 161 | end 162 | 163 | end 164 | 165 | end 166 | -------------------------------------------------------------------------------- /lib/seer/line_chart.rb: -------------------------------------------------------------------------------- 1 | module Seer 2 | 3 | # =USAGE 4 | # 5 | # In your controller: 6 | # 7 | # @data = Widgets.all # Must be an array of objects that respond to the specidied data method 8 | # # (In this example, 'quantity' 9 | # 10 | # @series = @data.map{|w| w.widget_stats} # An array of arrays 11 | # 12 | # In your view: 13 | # 14 | # 15 | # 16 | # <%= Seer::visualize( 17 | # @data, 18 | # :as => :line_chart, 19 | # :in_element => 'chart', 20 | # :series => { 21 | # :series_label => 'name', 22 | # :data_label => 'date', 23 | # :data_method => 'quantity', 24 | # :data_series => @series 25 | # }, 26 | # :chart_options => { 27 | # :height => 300, 28 | # :width => 300, 29 | # :axis_font_size => 11, 30 | # :colors => ['#7e7587','#990000','#009900'], 31 | # :title => "Widget Quantities", 32 | # :point_size => 5 33 | # } 34 | # ) 35 | # -%> 36 | # 37 | # For details on the chart options, see the Google API docs at 38 | # http://code.google.com/apis/visualization/documentation/gallery/linechart.html 39 | # 40 | class LineChart 41 | 42 | include Seer::Chart 43 | 44 | # Graph options 45 | attr_accessor :axis_color, :axis_background_color, :axis_font_size, :background_color, :border_color, :enable_tooltip, :focus_border_color, :height, :legend, :legend_background_color, :legend_font_size, :legend_text_color, :line_size, :log_scale, :max, :min, :point_size, :reverse_axis, :show_categories, :smooth_line, :title, :title_x, :title_y, :title_color, :title_font_size, :tooltip_font_size, :tooltip_height, :number, :tooltip_width, :width 46 | 47 | # Graph data 48 | attr_accessor :data, :data_label, :data_method, :data_series, :data_table, :series_label 49 | 50 | def initialize(args={}) #:nodoc: 51 | 52 | # Standard options 53 | args.each{ |method,arg| self.send("#{method}=",arg) if self.respond_to?(method) } 54 | 55 | # Chart options 56 | args[:chart_options].each{ |method, arg| self.send("#{method}=",arg) if self.respond_to?(method) } 57 | 58 | # Handle defaults 59 | @colors ||= args[:chart_options][:colors] || DEFAULT_COLORS 60 | @legend ||= args[:chart_options][:legend] || DEFAULT_LEGEND_LOCATION 61 | @height ||= args[:chart_options][:height] || DEFAULT_HEIGHT 62 | @width ||= args[:chart_options][:width] || DEFAULT_WIDTH 63 | 64 | @data_table = [] 65 | 66 | end 67 | 68 | def data_columns #:nodoc: 69 | _data_columns = " data.addRows(#{data_rows.size});\r" 70 | _data_columns << " data.addColumn('string', 'Date');\r" 71 | if data.first.respond_to?(series_label) 72 | data.each{ |datum| _data_columns << " data.addColumn('number', '#{datum.send(series_label)}');\r" } 73 | else 74 | data.each{ |datum| _data_columns << " data.addColumn('number', '#{series_label}');\r" } 75 | end 76 | _data_columns 77 | end 78 | 79 | def data_table #:nodoc: 80 | _rows = data_rows 81 | _rows.each_with_index do |r,i| 82 | @data_table << " data.setCell(#{i}, 0,'#{r}');\r" 83 | end 84 | data_series.each_with_index do |column,i| 85 | column.each_with_index do |c,j| 86 | @data_table << "data.setCell(#{j},#{i+1},#{c.send(data_method)});\r" 87 | end 88 | end 89 | @data_table 90 | end 91 | 92 | def data_rows 93 | data_series.inject([]) do |rows, element| 94 | rows |= element.map { |e| e.send(data_label) } 95 | end 96 | end 97 | 98 | def nonstring_options #:nodoc: 99 | [ :axis_font_size, :colors, :enable_tooltip, :height, :legend_font_size, :line_size, :log_scale, :max, :min, :point_size, :reverse_axis, :show_categories, :smooth_line, :title_font_size, :tooltip_font_size, :tooltip_height, :tooltip_width, :width] 100 | end 101 | 102 | def string_options #:nodoc: 103 | [ :axis_color, :axis_background_color, :background_color, :border_color, :focus_border_color, :legend, :legend_background_color, :legend_text_color, :title, :title_x, :title_y, :title_color ] 104 | end 105 | 106 | def to_js #:nodoc: 107 | 108 | %{ 109 | 123 | } 124 | end 125 | 126 | # ====================================== Class Methods ========================================= 127 | 128 | def self.render(data, args) #:nodoc: 129 | graph = Seer::LineChart.new( 130 | :data => data, 131 | :series_label => args[:series][:series_label], 132 | :data_series => args[:series][:data_series], 133 | :data_label => args[:series][:data_label], 134 | :data_method => args[:series][:data_method], 135 | :chart_options => args[:chart_options], 136 | :chart_element => args[:in_element] || 'chart' 137 | ) 138 | graph.to_js 139 | end 140 | 141 | end 142 | 143 | end 144 | -------------------------------------------------------------------------------- /lib/seer/pie_chart.rb: -------------------------------------------------------------------------------- 1 | module Seer 2 | 3 | # =USAGE 4 | # 5 | # In your controller: 6 | # 7 | # @data = Widgets.all # Must be an array of objects that respond to the specidied data method 8 | # # (In this example, 'quantity' 9 | # 10 | # In your view: 11 | # 12 | # 13 | # 14 | # <%= Seer::visualize( 15 | # @data, 16 | # :as => :pie_chart, 17 | # :series => {:series_label => 'name', :data_method => 'quantity'}, 18 | # :chart_options => { 19 | # :height => 300, 20 | # :width => 300, 21 | # :axis_font_size => 11, 22 | # :title => "Widget Quantities", 23 | # :point_size => 5, 24 | # :is_3_d => true 25 | # } 26 | # ) 27 | # -%> 28 | # 29 | # For details on the chart options, see the Google API docs at 30 | # http://code.google.com/apis/visualization/documentation/gallery/piechart.html 31 | # 32 | class PieChart 33 | 34 | include Seer::Chart 35 | 36 | # Chart options accessors 37 | attr_accessor :background_color, :border_color, :enable_tooltip, :focus_border_color, :height, :is_3_d, :legend, :legend_background_color, :legend_font_size, :legend_text_color, :pie_join_angle, :pie_minimal_angle, :title, :title_x, :title_y, :title_color, :title_font_size, :tooltip_font_size, :tooltip_height, :tooltip_width, :width 38 | 39 | # Graph data 40 | attr_accessor :data, :data_method, :data_table, :label_method 41 | 42 | def initialize(args={}) #:nodoc: 43 | 44 | # Standard options 45 | args.each{ |method,arg| self.send("#{method}=",arg) if self.respond_to?(method) } 46 | 47 | # Chart options 48 | args[:chart_options].each{ |method, arg| self.send("#{method}=",arg) if self.respond_to?(method) } 49 | 50 | # Handle defaults 51 | @colors ||= args[:chart_options][:colors] || DEFAULT_COLORS 52 | @legend ||= args[:chart_options][:legend] || DEFAULT_LEGEND_LOCATION 53 | @height ||= args[:chart_options][:height] || DEFAULT_HEIGHT 54 | @width ||= args[:chart_options][:width] || DEFAULT_WIDTH 55 | @is_3_d ||= args[:chart_options][:is_3_d] 56 | 57 | @data_table = [] 58 | 59 | end 60 | 61 | def data_table #:nodoc: 62 | data.each_with_index do |datum, column| 63 | @data_table << [ 64 | " data.setValue(#{column}, 0,'#{datum.send(label_method)}');\r", 65 | " data.setValue(#{column}, 1, #{datum.send(data_method)});\r" 66 | ] 67 | end 68 | @data_table 69 | end 70 | 71 | def is_3_d #:nodoc: 72 | @is_3_d.blank? ? false : @is_3_d 73 | end 74 | 75 | def nonstring_options #:nodoc: 76 | [: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] 77 | end 78 | 79 | def string_options #:nodoc: 80 | [:background_color, :border_color, :focus_border_color, :legend, :legend_background_color, :legend_text_color, :title, :title_color] 81 | end 82 | 83 | def to_js #:nodoc: 84 | 85 | %{ 86 | 100 | } 101 | end 102 | 103 | def self.render(data, args) #:nodoc: 104 | graph = Seer::PieChart.new( 105 | :data => data, 106 | :label_method => args[:series][:series_label], 107 | :data_method => args[:series][:data_method], 108 | :chart_options => args[:chart_options], 109 | :chart_element => args[:in_element] || 'chart' 110 | ) 111 | graph.to_js 112 | end 113 | 114 | end 115 | 116 | end 117 | -------------------------------------------------------------------------------- /rdoc/classes/Seer.html: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 8 |Module | 53 |Seer | 54 |
In: | 57 |
58 |
59 | lib/seer/area_chart.rb
60 |
61 | 62 | 63 | lib/seer/bar_chart.rb 64 | 65 | 66 | 67 | lib/seer/chart.rb 68 | 69 | 70 | 71 | lib/seer/column_chart.rb 72 | 73 | 74 | 75 | lib/seer/gauge.rb 76 | 77 | 78 | 79 | lib/seer/line_chart.rb 80 | 81 | 82 | 83 | lib/seer/pie_chart.rb 84 | 85 | 86 | 87 | lib/seer.rb 88 | 89 | 90 | |
91 |
VISUALIZERS | 142 |= | 143 |[:area_chart, :bar_chart, :column_chart, :gauge, :line_chart, :pie_chart] | 144 |
172 | # File lib/seer.rb, line 22 173 | def self.init_visualization 174 | %{<script type="text/javascript" src="http://www.google.com/jsapi"></script> } 175 | end 176 |177 |
195 | # File lib/seer.rb, line 26 196 | def self.visualize(data, args={}) 197 | raise ArgumentError, "Seer: Invalid visualizer: #{args[:as]}" unless args[:as] && VISUALIZERS.include?(args[:as]) 198 | raise ArgumentError, "Seer: No data provided!" unless data && ! data.empty? 199 | self.send(args[:as], data, args) 200 | end 201 |202 |
Class | 53 |Seer::AreaChart | 54 |
In: | 57 |
58 |
59 | lib/seer/area_chart.rb
60 |
61 | 62 | |
63 |
Parent: | 67 |68 | Object 69 | | 70 |
84 | In your controller: 85 |
86 |87 | @data = Widgets.all # Must be an array, and must respond 88 | # to the data method specified below (in this example, 'quantity') 89 | 90 | @series = @data.map{|w| w.widget_stats} # An array of arrays 91 |92 |
93 | In your view: 94 |
95 |96 | <div id="chart" class="chart"></div> 97 | 98 | <%= Seer::visualize( 99 | @data, 100 | :as => :area_chart, 101 | :in_element => 'chart', 102 | :series => { 103 | :series_label => 'name', 104 | :data_label => 'date', 105 | :data_method => 'quantity', 106 | :data_series => @series 107 | }, 108 | :chart_options => { 109 | :height => 300, 110 | :width => 300, 111 | :axis_font_size => 11, 112 | :colors => ['#7e7587','#990000','#009900'], 113 | :title => "Widget Quantities", 114 | :point_size => 5 115 | } 116 | ) 117 | -%> 118 |119 |
120 | For details on the chart options, see the Google API docs at code.google.com/apis/visualization/documentation/gallery/areachart.html 122 |
123 | 124 |axis_background_color | 155 |[RW] | 156 |157 | Graph options 158 | 159 | | 160 |
axis_color | 163 |[RW] | 164 |165 | Graph options 166 | 167 | | 168 |
axis_font_size | 171 |[RW] | 172 |173 | Graph options 174 | 175 | | 176 |
background_color | 179 |[RW] | 180 |181 | Graph options 182 | 183 | | 184 |
border_color | 187 |[RW] | 188 |189 | Graph options 190 | 191 | | 192 |
data | 195 |[RW] | 196 |197 | Graph data 198 | 199 | | 200 |
data_label | 203 |[RW] | 204 |205 | Graph data 206 | 207 | | 208 |
data_method | 211 |[RW] | 212 |213 | Graph data 214 | 215 | | 216 |
data_series | 219 |[RW] | 220 |221 | Graph data 222 | 223 | | 224 |
data_table | 227 |[RW] | 228 |229 | Graph options 230 | 231 | | 232 |
enable_tooltip | 235 |[RW] | 236 |237 | Graph options 238 | 239 | | 240 |
focus_border_color | 243 |[RW] | 244 |245 | Graph options 246 | 247 | | 248 |
height | 251 |[RW] | 252 |253 | Graph options 254 | 255 | | 256 |
is_stacked | 259 |[RW] | 260 |261 | Graph options 262 | 263 | | 264 |
legend | 267 |[RW] | 268 |269 | Graph options 270 | 271 | | 272 |
legend_background_color | 275 |[RW] | 276 |277 | Graph options 278 | 279 | | 280 |
legend_font_size | 283 |[RW] | 284 |285 | Graph options 286 | 287 | | 288 |
legend_text_color | 291 |[RW] | 292 |293 | Graph options 294 | 295 | | 296 |
line_size | 299 |[RW] | 300 |301 | Graph options 302 | 303 | | 304 |
log_scale | 307 |[RW] | 308 |309 | Graph options 310 | 311 | | 312 |
max | 315 |[RW] | 316 |317 | Graph options 318 | 319 | | 320 |
min | 323 |[RW] | 324 |325 | Graph options 326 | 327 | | 328 |
number | 331 |[RW] | 332 |333 | Graph options 334 | 335 | | 336 |
point_size | 339 |[RW] | 340 |341 | Graph options 342 | 343 | | 344 |
reverse_axis | 347 |[RW] | 348 |349 | Graph options 350 | 351 | | 352 |
series_label | 355 |[RW] | 356 |357 | Graph data 358 | 359 | | 360 |
show_categories | 363 |[RW] | 364 |365 | Graph options 366 | 367 | | 368 |
title | 371 |[RW] | 372 |373 | Graph options 374 | 375 | | 376 |
title_color | 379 |[RW] | 380 |381 | Graph options 382 | 383 | | 384 |
title_font_size | 387 |[RW] | 388 |389 | Graph options 390 | 391 | | 392 |
title_x | 395 |[RW] | 396 |397 | Graph options 398 | 399 | | 400 |
title_y | 403 |[RW] | 404 |405 | Graph options 406 | 407 | | 408 |
tooltip_font_size | 411 |[RW] | 412 |413 | Graph options 414 | 415 | | 416 |
tooltip_height | 419 |[RW] | 420 |421 | Graph options 422 | 423 | | 424 |
tooltip_width | 427 |[RW] | 428 |429 | Graph options 430 | 431 | | 432 |
width | 435 |[RW] | 436 |437 | Graph options 438 | 439 | | 440 |
Class | 53 |Seer::BarChart | 54 |
In: | 57 |
58 |
59 | lib/seer/bar_chart.rb
60 |
61 | 62 | |
63 |
Parent: | 67 |68 | Object 69 | | 70 |
84 | In your controller: 85 |
86 |87 | @data = Widgets.all # Must be an array, and must respond 88 | # to the data method specified below (in this example, 'quantity') 89 |90 |
91 | In your view: 92 |
93 |94 | <div id="chart" class="chart"></div> 95 | 96 | <%= Seer::visualize( 97 | @widgets, 98 | :as => :bar_chart, 99 | :in_element => 'chart', 100 | :series => {:series_label => 'name', :data_method => 'quantity'}, 101 | :chart_options => { 102 | :height => 300, 103 | :width => 200 * @widgets.size, 104 | :is_3_d => false, 105 | :legend => 'none', 106 | :colors => ["#990000"], 107 | :title => "Widget Quantities", 108 | :title_x => 'Quantity', 109 | :title_y => 'Widgets' 110 | } 111 | ) 112 | -%> 113 |114 |
115 | Colors are treated differently for 2d and 3d graphs. If you set is_3_d to 116 | true, set the graph colors like this: 117 |
118 |119 | :colors => "[{color:'#990000', darker:'#660000'}]", 120 |121 |
122 | For details on the chart options, see the Google API docs at code.google.com/apis/visualization/documentation/gallery/barchart.html 124 |
125 | 126 |axis_background_color | 157 |[RW] | 158 |159 | Chart options accessors 160 | 161 | | 162 |
axis_color | 165 |[RW] | 166 |167 | Chart options accessors 168 | 169 | | 170 |
axis_font_size | 173 |[RW] | 174 |175 | Chart options accessors 176 | 177 | | 178 |
background_color | 181 |[RW] | 182 |183 | Chart options accessors 184 | 185 | | 186 |
border_color | 189 |[RW] | 190 |191 | Chart options accessors 192 | 193 | | 194 |
data | 197 |[RW] | 198 |199 | Graph data 200 | 201 | | 202 |
data_method | 205 |[RW] | 206 |207 | Graph data 208 | 209 | | 210 |
data_table | 213 |[RW] | 214 |215 | Chart options accessors 216 | 217 | | 218 |
enable_tooltip | 221 |[RW] | 222 |223 | Chart options accessors 224 | 225 | | 226 |
focus_border_color | 229 |[RW] | 230 |231 | Chart options accessors 232 | 233 | | 234 |
height | 237 |[RW] | 238 |239 | Chart options accessors 240 | 241 | | 242 |
is_3_d | 245 |[RW] | 246 |247 | Chart options accessors 248 | 249 | | 250 |
is_stacked | 253 |[RW] | 254 |255 | Chart options accessors 256 | 257 | | 258 |
label_method | 261 |[RW] | 262 |263 | Graph data 264 | 265 | | 266 |
legend | 269 |[RW] | 270 |271 | Chart options accessors 272 | 273 | | 274 |
legend_background_color | 277 |[RW] | 278 |279 | Chart options accessors 280 | 281 | | 282 |
legend_font_size | 285 |[RW] | 286 |287 | Chart options accessors 288 | 289 | | 290 |
legend_text_color | 293 |[RW] | 294 |295 | Chart options accessors 296 | 297 | | 298 |
log_scale | 301 |[RW] | 302 |303 | Chart options accessors 304 | 305 | | 306 |
max | 309 |[RW] | 310 |311 | Chart options accessors 312 | 313 | | 314 |
min | 317 |[RW] | 318 |319 | Chart options accessors 320 | 321 | | 322 |
reverse_axis | 325 |[RW] | 326 |327 | Chart options accessors 328 | 329 | | 330 |
show_categories | 333 |[RW] | 334 |335 | Chart options accessors 336 | 337 | | 338 |
title | 341 |[RW] | 342 |343 | Chart options accessors 344 | 345 | | 346 |
title_color | 349 |[RW] | 350 |351 | Chart options accessors 352 | 353 | | 354 |
title_font_size | 357 |[RW] | 358 |359 | Chart options accessors 360 | 361 | | 362 |
title_x | 365 |[RW] | 366 |367 | Chart options accessors 368 | 369 | | 370 |
title_y | 373 |[RW] | 374 |375 | Chart options accessors 376 | 377 | | 378 |
tooltip_font_size | 381 |[RW] | 382 |383 | Chart options accessors 384 | 385 | | 386 |
tooltip_height | 389 |[RW] | 390 |391 | Chart options accessors 392 | 393 | | 394 |
tooltip_width | 397 |[RW] | 398 |399 | Chart options accessors 400 | 401 | | 402 |
width | 405 |[RW] | 406 |407 | Chart options accessors 408 | 409 | | 410 |
Class | 53 |Seer::ColumnChart | 54 |
In: | 57 |
58 |
59 | lib/seer/column_chart.rb
60 |
61 | 62 | |
63 |
Parent: | 67 |68 | Object 69 | | 70 |
84 | In your controller: 85 |
86 |87 | @data = Widgets.all # Must be an array, and must respond 88 | # to the data method specified below (in this example, 'quantity') 89 |90 |
91 | In your view: 92 |
93 |94 | <div id="chart" class="chart"></div> 95 | 96 | <%= Seer::visualize( 97 | @widgets, 98 | :as => :column_chart, 99 | :in_element => 'chart', 100 | :series => {:series_label => 'name', :data_method => 'quantity'}, 101 | :chart_options => { 102 | :height => 300, 103 | :width => 300, 104 | :is_3_d => true, 105 | :legend => 'none', 106 | :colors => "[{color:'#990000', darker:'#660000'}]", 107 | :title => "Widget Quantities", 108 | :title_x => 'Widgets', 109 | :title_y => 'Quantities' 110 | } 111 | ) 112 | -%> 113 |114 |
115 | Colors are treated differently for 2d and 3d graphs. If you set is_3_d to 116 | false, set the graph color like this: 117 |
118 |119 | :colors => "#990000" 120 |121 |
122 | For details on the chart options, see the Google API docs at code.google.com/apis/visualization/documentation/gallery/columnchart.html 124 |
125 | 126 |axis_background_color | 157 |[RW] | 158 |159 | Chart options accessors 160 | 161 | | 162 |
axis_color | 165 |[RW] | 166 |167 | Chart options accessors 168 | 169 | | 170 |
axis_font_size | 173 |[RW] | 174 |175 | Chart options accessors 176 | 177 | | 178 |
background_color | 181 |[RW] | 182 |183 | Chart options accessors 184 | 185 | | 186 |
border_color | 189 |[RW] | 190 |191 | Chart options accessors 192 | 193 | | 194 |
data | 197 |[RW] | 198 |199 | Graph data 200 | 201 | | 202 |
data_method | 205 |[RW] | 206 |207 | Graph data 208 | 209 | | 210 |
data_table | 213 |[RW] | 214 |215 | Graph data 216 | 217 | | 218 |
enable_tooltip | 221 |[RW] | 222 |223 | Chart options accessors 224 | 225 | | 226 |
focus_border_color | 229 |[RW] | 230 |231 | Chart options accessors 232 | 233 | | 234 |
height | 237 |[RW] | 238 |239 | Chart options accessors 240 | 241 | | 242 |
is_3_d | 245 |[RW] | 246 |247 | Chart options accessors 248 | 249 | | 250 |
is_stacked | 253 |[RW] | 254 |255 | Chart options accessors 256 | 257 | | 258 |
label_method | 261 |[RW] | 262 |263 | Graph data 264 | 265 | | 266 |
legend | 269 |[RW] | 270 |271 | Chart options accessors 272 | 273 | | 274 |
legend_background_color | 277 |[RW] | 278 |279 | Chart options accessors 280 | 281 | | 282 |
legend_font_size | 285 |[RW] | 286 |287 | Chart options accessors 288 | 289 | | 290 |
legend_text_color | 293 |[RW] | 294 |295 | Chart options accessors 296 | 297 | | 298 |
log_scale | 301 |[RW] | 302 |303 | Chart options accessors 304 | 305 | | 306 |
max | 309 |[RW] | 310 |311 | Chart options accessors 312 | 313 | | 314 |
min | 317 |[RW] | 318 |319 | Chart options accessors 320 | 321 | | 322 |
reverse_axis | 325 |[RW] | 326 |327 | Chart options accessors 328 | 329 | | 330 |
show_categories | 333 |[RW] | 334 |335 | Chart options accessors 336 | 337 | | 338 |
title | 341 |[RW] | 342 |343 | Chart options accessors 344 | 345 | | 346 |
title_color | 349 |[RW] | 350 |351 | Chart options accessors 352 | 353 | | 354 |
title_font_size | 357 |[RW] | 358 |359 | Chart options accessors 360 | 361 | | 362 |
title_x | 365 |[RW] | 366 |367 | Chart options accessors 368 | 369 | | 370 |
title_y | 373 |[RW] | 374 |375 | Chart options accessors 376 | 377 | | 378 |
tooltip_font_size | 381 |[RW] | 382 |383 | Chart options accessors 384 | 385 | | 386 |
tooltip_height | 389 |[RW] | 390 |391 | Chart options accessors 392 | 393 | | 394 |
tooltip_width | 397 |[RW] | 398 |399 | Chart options accessors 400 | 401 | | 402 |
width | 405 |[RW] | 406 |407 | Chart options accessors 408 | 409 | | 410 |
Class | 53 |Seer::Gauge | 54 |
In: | 57 |
58 |
59 | lib/seer/gauge.rb
60 |
61 | 62 | |
63 |
Parent: | 67 |68 | Object 69 | | 70 |
84 | In your controller: 85 |
86 |87 | @data = Widgets.all # Must be an array, and must respond 88 | # to the data method specified below (in this example, 'quantity') 89 |90 |
91 | In your view: 92 |
93 |94 | <div id="chart" class="chart"></div> 95 | 96 | <%= Seer::visualize( 97 | @data, 98 | :as => :gauge, 99 | :in_element => 'chart', 100 | :series => {:series_label => 'name', :data_method => 'quantity'}, 101 | :chart_options => { 102 | :green_from => 0, 103 | :green_to => 50, 104 | :height => 300, 105 | :max => 100, 106 | :min => 0, 107 | :minor_ticks => 5, 108 | :red_from => 76, 109 | :red_to => 100, 110 | :width => 600, 111 | :yellow_from => 51, 112 | :yellow_to => 75 113 | } 114 | ) 115 | -%> 116 |117 |
118 | For details on the chart options, see the Google API docs at code.google.com/apis/visualization/documentation/gallery/gauge.html 120 |
121 | 122 |data | 153 |[RW] | 154 |155 | Graph data 156 | 157 | | 158 |
data_method | 161 |[RW] | 162 |163 | Graph data 164 | 165 | | 166 |
data_table | 169 |[RW] | 170 |171 | Graph data 172 | 173 | | 174 |
green_from | 177 |[RW] | 178 |179 | Chart options accessors 180 | 181 | | 182 |
green_to | 185 |[RW] | 186 |187 | Chart options accessors 188 | 189 | | 190 |
height | 193 |[RW] | 194 |195 | Chart options accessors 196 | 197 | | 198 |
label_method | 201 |[RW] | 202 |203 | Graph data 204 | 205 | | 206 |
major_ticks | 209 |[RW] | 210 |211 | Chart options accessors 212 | 213 | | 214 |
max | 217 |[RW] | 218 |219 | Chart options accessors 220 | 221 | | 222 |
min | 225 |[RW] | 226 |227 | Chart options accessors 228 | 229 | | 230 |
minor_ticks | 233 |[RW] | 234 |235 | Chart options accessors 236 | 237 | | 238 |
red_from | 241 |[RW] | 242 |243 | Chart options accessors 244 | 245 | | 246 |
red_to | 249 |[RW] | 250 |251 | Chart options accessors 252 | 253 | | 254 |
width | 257 |[RW] | 258 |259 | Chart options accessors 260 | 261 | | 262 |
yellow_from | 265 |[RW] | 266 |267 | Chart options accessors 268 | 269 | | 270 |
yellow_to | 273 |[RW] | 274 |275 | Chart options accessors 276 | 277 | | 278 |
Class | 53 |Seer::LineChart | 54 |
In: | 57 |
58 |
59 | lib/seer/line_chart.rb
60 |
61 | 62 | |
63 |
Parent: | 67 |68 | Object 69 | | 70 |
84 | In your controller: 85 |
86 |87 | @data = Widgets.all # Must be an array of objects that respond to the specidied data method 88 | # (In this example, 'quantity' 89 | 90 | @series = @data.map{|w| w.widget_stats} # An array of arrays 91 |92 |
93 | In your view: 94 |
95 |96 | <div id="chart" class="chart"></div> 97 | 98 | <%= Seer::visualize( 99 | @data, 100 | :as => :line_chart, 101 | :in_element => 'chart', 102 | :series => { 103 | :series_label => 'name', 104 | :data_label => 'date', 105 | :data_method => 'quantity', 106 | :data_series => @series 107 | }, 108 | :chart_options => { 109 | :height => 300, 110 | :width => 300, 111 | :axis_font_size => 11, 112 | :colors => ['#7e7587','#990000','#009900'], 113 | :title => "Widget Quantities", 114 | :point_size => 5 115 | } 116 | ) 117 | -%> 118 |119 |
120 | For details on the chart options, see the Google API docs at code.google.com/apis/visualization/documentation/gallery/linechart.html 122 |
123 | 124 |axis_background_color | 155 |[RW] | 156 |157 | Graph options 158 | 159 | | 160 |
axis_color | 163 |[RW] | 164 |165 | Graph options 166 | 167 | | 168 |
axis_font_size | 171 |[RW] | 172 |173 | Graph options 174 | 175 | | 176 |
background_color | 179 |[RW] | 180 |181 | Graph options 182 | 183 | | 184 |
border_color | 187 |[RW] | 188 |189 | Graph options 190 | 191 | | 192 |
data | 195 |[RW] | 196 |197 | Graph data 198 | 199 | | 200 |
data_label | 203 |[RW] | 204 |205 | Graph data 206 | 207 | | 208 |
data_method | 211 |[RW] | 212 |213 | Graph data 214 | 215 | | 216 |
data_series | 219 |[RW] | 220 |221 | Graph data 222 | 223 | | 224 |
data_table | 227 |[RW] | 228 |229 | Graph data 230 | 231 | | 232 |
enable_tooltip | 235 |[RW] | 236 |237 | Graph options 238 | 239 | | 240 |
focus_border_color | 243 |[RW] | 244 |245 | Graph options 246 | 247 | | 248 |
height | 251 |[RW] | 252 |253 | Graph options 254 | 255 | | 256 |
legend | 259 |[RW] | 260 |261 | Graph options 262 | 263 | | 264 |
legend_background_color | 267 |[RW] | 268 |269 | Graph options 270 | 271 | | 272 |
legend_font_size | 275 |[RW] | 276 |277 | Graph options 278 | 279 | | 280 |
legend_text_color | 283 |[RW] | 284 |285 | Graph options 286 | 287 | | 288 |
line_size | 291 |[RW] | 292 |293 | Graph options 294 | 295 | | 296 |
log_scale | 299 |[RW] | 300 |301 | Graph options 302 | 303 | | 304 |
max | 307 |[RW] | 308 |309 | Graph options 310 | 311 | | 312 |
min | 315 |[RW] | 316 |317 | Graph options 318 | 319 | | 320 |
number | 323 |[RW] | 324 |325 | Graph options 326 | 327 | | 328 |
point_size | 331 |[RW] | 332 |333 | Graph options 334 | 335 | | 336 |
reverse_axis | 339 |[RW] | 340 |341 | Graph options 342 | 343 | | 344 |
series_label | 347 |[RW] | 348 |349 | Graph data 350 | 351 | | 352 |
show_categories | 355 |[RW] | 356 |357 | Graph options 358 | 359 | | 360 |
smooth_line | 363 |[RW] | 364 |365 | Graph options 366 | 367 | | 368 |
title | 371 |[RW] | 372 |373 | Graph options 374 | 375 | | 376 |
title_color | 379 |[RW] | 380 |381 | Graph options 382 | 383 | | 384 |
title_font_size | 387 |[RW] | 388 |389 | Graph options 390 | 391 | | 392 |
title_x | 395 |[RW] | 396 |397 | Graph options 398 | 399 | | 400 |
title_y | 403 |[RW] | 404 |405 | Graph options 406 | 407 | | 408 |
tooltip_font_size | 411 |[RW] | 412 |413 | Graph options 414 | 415 | | 416 |
tooltip_height | 419 |[RW] | 420 |421 | Graph options 422 | 423 | | 424 |
tooltip_width | 427 |[RW] | 428 |429 | Graph options 430 | 431 | | 432 |
width | 435 |[RW] | 436 |437 | Graph options 438 | 439 | | 440 |
Class | 53 |Seer::PieChart | 54 |
In: | 57 |
58 |
59 | lib/seer/pie_chart.rb
60 |
61 | 62 | |
63 |
Parent: | 67 |68 | Object 69 | | 70 |
84 | In your controller: 85 |
86 |87 | @data = Widgets.all # Must be an array of objects that respond to the specidied data method 88 | # (In this example, 'quantity' 89 |90 |
91 | In your view: 92 |
93 |94 | <div id="chart" class="chart"></div> 95 | 96 | <%= Seer::visualize( 97 | @data, 98 | :as => :pie_chart, 99 | :series => {:series_label => 'name', :data_method => 'quantity'}, 100 | :chart_options => { 101 | :height => 300, 102 | :width => 300, 103 | :axis_font_size => 11, 104 | :title => "Widget Quantities", 105 | :point_size => 5, 106 | :is_3_d => true 107 | } 108 | ) 109 | -%> 110 |111 |
112 | For details on the chart options, see the Google API docs at code.google.com/apis/visualization/documentation/gallery/piechart.html 114 |
115 | 116 |background_color | 147 |[RW] | 148 |149 | Chart options accessors 150 | 151 | | 152 |
border_color | 155 |[RW] | 156 |157 | Chart options accessors 158 | 159 | | 160 |
data | 163 |[RW] | 164 |165 | Graph data 166 | 167 | | 168 |
data_method | 171 |[RW] | 172 |173 | Graph data 174 | 175 | | 176 |
data_table | 179 |[RW] | 180 |181 | Graph data 182 | 183 | | 184 |
enable_tooltip | 187 |[RW] | 188 |189 | Chart options accessors 190 | 191 | | 192 |
focus_border_color | 195 |[RW] | 196 |197 | Chart options accessors 198 | 199 | | 200 |
height | 203 |[RW] | 204 |205 | Chart options accessors 206 | 207 | | 208 |
is_3_d | 211 |[RW] | 212 |213 | Chart options accessors 214 | 215 | | 216 |
label_method | 219 |[RW] | 220 |221 | Graph data 222 | 223 | | 224 |
legend | 227 |[RW] | 228 |229 | Chart options accessors 230 | 231 | | 232 |
legend_background_color | 235 |[RW] | 236 |237 | Chart options accessors 238 | 239 | | 240 |
legend_font_size | 243 |[RW] | 244 |245 | Chart options accessors 246 | 247 | | 248 |
legend_text_color | 251 |[RW] | 252 |253 | Chart options accessors 254 | 255 | | 256 |
pie_join_angle | 259 |[RW] | 260 |261 | Chart options accessors 262 | 263 | | 264 |
pie_minimal_angle | 267 |[RW] | 268 |269 | Chart options accessors 270 | 271 | | 272 |
title | 275 |[RW] | 276 |277 | Chart options accessors 278 | 279 | | 280 |
title_color | 283 |[RW] | 284 |285 | Chart options accessors 286 | 287 | | 288 |
title_font_size | 291 |[RW] | 292 |293 | Chart options accessors 294 | 295 | | 296 |
title_x | 299 |[RW] | 300 |301 | Chart options accessors 302 | 303 | | 304 |
title_y | 307 |[RW] | 308 |309 | Chart options accessors 310 | 311 | | 312 |
tooltip_font_size | 315 |[RW] | 316 |317 | Chart options accessors 318 | 319 | | 320 |
tooltip_height | 323 |[RW] | 324 |325 | Chart options accessors 326 | 327 | | 328 |
tooltip_width | 331 |[RW] | 332 |333 | Chart options accessors 334 | 335 | | 336 |
width | 339 |[RW] | 340 |341 | Chart options accessors 342 | 343 | | 344 |
Path: | 54 |README.rdoc 55 | | 56 |
Last Update: | 59 |Tue Feb 16 14:10:55 -0600 2010 | 60 |
74 | Seer is a lightweight, semantically rich 75 | wrapper for the Google Visualization API. It allows you to easily create a 76 | visualization of data in a variety of formats, including area charts, bar 77 | charts, column charts, gauges, line charts, and pie charts. 78 |
79 |81 | Add the following to the head of the page that will display a chart, or add 82 | it to your layout file: 83 |
84 |85 | <%= Seer::init_visualization -%> 86 |87 |
88 | Gather the data you want to visualize in an instance variable in your 89 | controller, then use the visualize method to insert the appropriate chart 90 | in your view. 91 |
92 |94 | In your controller: 95 |
96 |97 | # @data must be an array, and each object in the array must respond to the data method specified 98 | # in the visualize call (in this example, 'quantity') 99 | @data = Widget.all 100 |101 |
102 | In your view: 103 |
104 |105 | <div id="chart" class="chart"></div> 106 | 107 | <%= Seer::visualize( 108 | @widgets, 109 | :as => :bar_chart, 110 | :in_element => 'chart', 111 | :series => {:series_label => 'name', :data_method => 'quantity'}, 112 | :chart_options => { 113 | :height => 300, 114 | :width => 200 * @widgets.size, 115 | :is_3_d => false, 116 | :legend => 'none', 117 | :colors => ["#990000"], 118 | :title => "Widget Quantities", 119 | :title_x => 'Quantity', 120 | :title_y => 'Widgets' 121 | } 122 | ) 123 | -%> 124 |125 |
126 | For examples of additional chart types, refer to the documentation for each 127 | of the individual chart objects. 128 |
129 |130 | Copyright (c) 2010 Corey Ehmke / SEO Logic, released under the MIT license 131 |
132 | 133 |Path: | 54 |lib/seer/area_chart.rb 55 | | 56 |
Last Update: | 59 |Tue Feb 16 17:31:17 -0600 2010 | 60 |
Path: | 54 |lib/seer/bar_chart.rb 55 | | 56 |
Last Update: | 59 |Tue Feb 16 17:31:17 -0600 2010 | 60 |
Path: | 54 |lib/seer/chart.rb 55 | | 56 |
Last Update: | 59 |Tue Feb 16 14:01:36 -0600 2010 | 60 |
Path: | 54 |lib/seer/column_chart.rb 55 | | 56 |
Last Update: | 59 |Tue Feb 16 17:31:18 -0600 2010 | 60 |
Path: | 54 |lib/seer/gauge.rb 55 | | 56 |
Last Update: | 59 |Tue Feb 16 17:31:18 -0600 2010 | 60 |
Path: | 54 |lib/seer/line_chart.rb 55 | | 56 |
Last Update: | 59 |Tue Feb 16 17:31:18 -0600 2010 | 60 |
Path: | 54 |lib/seer/pie_chart.rb 55 | | 56 |
Last Update: | 59 |Tue Feb 16 17:31:18 -0600 2010 | 60 |
Path: | 54 |lib/seer.rb 55 | | 56 |
Last Update: | 59 |Tue Feb 16 11:00:49 -0600 2010 | 60 |