Class: Yeqs::Jquery::Highchart
- Inherits:
-
Object
- Object
- Yeqs::Jquery::Highchart
- Defined in:
- lib/yeqs_jquery/highchart.rb
Constant Summary collapse
- CANVAS_DEFAULT_HTML_OPTIONS =
{:style => "height: 300px, width:615px" }
- SERIES_OPTIONS =
%w(lines points bars shadowSize colors)
Instance Attribute Summary collapse
-
#data ⇒ Object
Returns the value of attribute data.
-
#html_options ⇒ Object
Returns the value of attribute html_options.
-
#options ⇒ Object
Returns the value of attribute options.
-
#placeholder ⇒ Object
(also: #canvas)
Returns the value of attribute placeholder.
Instance Method Summary collapse
-
#defaults_options ⇒ Object
title: legend: xAxis: yAxis: tooltip: credits: :plotOptions.
-
#filter(&block) ⇒ Object
Setup a filter that will be used to limit all datasets in the graph.
-
#initialize(canvas = nil, html_opts = {}) {|_self| ... } ⇒ Highchart
constructor
A new instance of Highchart.
-
#method_missing(meth, opts = {}) ⇒ Object
Pass other methods through to the javascript high_chart object.
-
#series(label, d, opts = {}) ⇒ Object
Add a simple series to the graph:.
Constructor Details
#initialize(canvas = nil, html_opts = {}) {|_self| ... } ⇒ Highchart
Returns a new instance of Highchart.
12 13 14 15 16 17 18 19 20 21 |
# File 'lib/yeqs_jquery/highchart.rb', line 12 def initialize(canvas = nil, html_opts = {}) @collection_filter = nil self.data ||= [] self. ||= {} self. self. = html_opts.reverse_merge(CANVAS_DEFAULT_HTML_OPTIONS) self.canvas = canvas if canvas yield self if block_given? end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(meth, opts = {}) ⇒ Object
Pass other methods through to the javascript high_chart object.
For instance: high_chart.grid(:color => "#699")
53 54 55 |
# File 'lib/yeqs_jquery/highchart.rb', line 53 def method_missing(meth, opts = {}) meth, opts end |
Instance Attribute Details
#data ⇒ Object
Returns the value of attribute data.
7 8 9 |
# File 'lib/yeqs_jquery/highchart.rb', line 7 def data @data end |
#html_options ⇒ Object
Returns the value of attribute html_options.
7 8 9 |
# File 'lib/yeqs_jquery/highchart.rb', line 7 def @html_options end |
#options ⇒ Object
Returns the value of attribute options.
7 8 9 |
# File 'lib/yeqs_jquery/highchart.rb', line 7 def @options end |
#placeholder ⇒ Object Also known as: canvas
Returns the value of attribute placeholder.
7 8 9 |
# File 'lib/yeqs_jquery/highchart.rb', line 7 def placeholder @placeholder end |
Instance Method Details
#defaults_options ⇒ Object
title: legend: xAxis: yAxis: tooltip: credits: :plotOptions
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/yeqs_jquery/highchart.rb', line 25 def self.title({ :text=>"example test title from plugin"}) self.legend({:layout=>"vertical", :style=>{:position=>'absolute', :bottom=>'auto', :left=>'150px', :top=>'150px'} , :borderWidth=> 1, :backgroundColor=>'#FFFFFF'}) self.x_axis( {:categories=> ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday'], :plotBands=> [{ :from=> 6.0,:to=> 6.5,:color=> 'rgba(68, 170, 213, .2)' }], :labels=>{ :align=>'right',:rotation=>45 } }) self.y_axis({:title=> {:text=> 'Fruit units'}, :labels=>{:align=>'right'} }) self.tooltip({ :enabled=>true }) self.credits({:enabled => false}) self.({ :areaspline => { :fillOpacity => 0.5 } }) self.chart({:defaultSeriesType=>"areaspline" , :renderTo => nil}) self.subtitle({}) end |
#filter(&block) ⇒ Object
Setup a filter that will be used to limit all datasets in the graph.
For instance, to limit the graph to positive amounts:
high_chart.filter {|collection| collection.select {|record| record.amount > 0 }}
62 63 64 |
# File 'lib/yeqs_jquery/highchart.rb', line 62 def filter(&block) @collection_filter = block end |
#series(label, d, opts = {}) ⇒ Object
Add a simple series to the graph:
data = [[0,5], [1,5], [2,5]]
@high_chart.series "Horizontal Line", data
@high_chart.series "Red Line", data, :color => '#f00' # or is it "'#f00'"
72 73 74 75 76 77 78 |
# File 'lib/yeqs_jquery/highchart.rb', line 72 def series(label, d, opts = {}) if opts.blank? @data << .merge(:name => label, :data => d) else @data << opts.merge(:name => label, :data => d) end end |