Class: LazyHighCharts::HighChart
- Inherits:
-
Object
- Object
- LazyHighCharts::HighChart
- Defined in:
- lib/lazy_high_charts/high_chart.rb
Constant Summary collapse
- SERIES_OPTIONS =
%w(data dataParser dataURL index legendIndex name stack type xAxis yAxis)
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.
-
#initialize(canvas = nil, html_opts = {}) ⇒ HighChart
constructor
A new instance of HighChart.
-
#method_missing(meth, opts = {}) ⇒ Object
Pass other methods through to the javascript high_chart object.
-
#series(opts = {}) ⇒ Object
Add a simple series to the graph:.
Constructor Details
#initialize(canvas = nil, html_opts = {}) ⇒ HighChart
Returns a new instance of HighChart.
9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/lazy_high_charts/high_chart.rb', line 9 def initialize(canvas = nil, html_opts = {}) @collection_filter = nil self.tap do |high_chart| high_chart.data ||= [] high_chart. ||= {} high_chart. high_chart. ||={} high_chart.canvas = canvas if canvas yield high_chart if block_given? end 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")
39 40 41 42 43 44 45 |
# File 'lib/lazy_high_charts/high_chart.rb', line 39 def method_missing(meth, opts = {}) if meth.to_s.end_with? '!' meth[0..-2].to_sym, opts else meth, opts end end |
Instance Attribute Details
#data ⇒ Object
Returns the value of attribute data.
5 6 7 |
# File 'lib/lazy_high_charts/high_chart.rb', line 5 def data @data end |
#html_options ⇒ Object
Returns the value of attribute html_options.
5 6 7 |
# File 'lib/lazy_high_charts/high_chart.rb', line 5 def @html_options end |
#options ⇒ Object
Returns the value of attribute options.
5 6 7 |
# File 'lib/lazy_high_charts/high_chart.rb', line 5 def @options end |
#placeholder ⇒ Object Also known as: canvas
Returns the value of attribute placeholder.
5 6 7 |
# File 'lib/lazy_high_charts/high_chart.rb', line 5 def placeholder @placeholder end |
Instance Method Details
#defaults_options ⇒ Object
title: legend: xAxis: yAxis: tooltip: credits: :plotOptions
23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/lazy_high_charts/high_chart.rb', line 23 def self.title({ :text=>"example test title from highcharts gem"}) self.legend({ :layout=>"vertical", :style=>{} }) self.xAxis({}) self.yAxis({ :title=> {:text=> nil}, :labels=>{} }) self.tooltip({ :enabled=>true }) self.credits({ :enabled => false}) self.plotOptions({ :areaspline => { } }) self.chart({ :defaultSeriesType=>"line" , :renderTo => nil}) self.subtitle({}) end |
#series(opts = {}) ⇒ Object
Add a simple series to the graph:
data = [[0,5], [1,5], [2,5]]
@high_chart.series :name=>'Updated', :data=>data
@high_chart.series :name=>'Updated', :data=>[5, 1, 6, 1, 5, 4, 9]
52 53 54 55 56 57 |
# File 'lib/lazy_high_charts/high_chart.rb', line 52 def series(opts = {}) @data ||= [] if not opts.empty? @data << OptionsKeyFilter.filter(opts.merge(:name => opts[:name], :data => opts[:data])) end end |