Class: FlexChart::Base
- Inherits:
-
Object
- Object
- FlexChart::Base
- Defined in:
- lib/flex_chart.rb
Instance Attribute Summary collapse
-
#color ⇒ Object
Returns the value of attribute color.
-
#fill_color ⇒ Object
Returns the value of attribute fill_color.
-
#series ⇒ Object
Returns the value of attribute series.
-
#title ⇒ Object
Returns the value of attribute title.
-
#x_axis_type ⇒ Object
Returns the value of attribute x_axis_type.
-
#x_label ⇒ Object
Returns the value of attribute x_label.
-
#y_axis_type ⇒ Object
Returns the value of attribute y_axis_type.
-
#y_label ⇒ Object
Returns the value of attribute y_label.
Instance Method Summary collapse
- #fix_color(color) ⇒ Object
-
#initialize(options = {}) ⇒ Base
constructor
A new instance of Base.
- #to_xml ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Base
Returns a new instance of Base.
5 6 7 8 9 |
# File 'lib/flex_chart.rb', line 5 def initialize( = {}) @series = [] @x_axis_type = "Linear" @y_axis_type = "Linear" end |
Instance Attribute Details
#color ⇒ Object
Returns the value of attribute color.
3 4 5 |
# File 'lib/flex_chart.rb', line 3 def color @color end |
#fill_color ⇒ Object
Returns the value of attribute fill_color.
3 4 5 |
# File 'lib/flex_chart.rb', line 3 def fill_color @fill_color end |
#series ⇒ Object
Returns the value of attribute series.
3 4 5 |
# File 'lib/flex_chart.rb', line 3 def series @series end |
#title ⇒ Object
Returns the value of attribute title.
3 4 5 |
# File 'lib/flex_chart.rb', line 3 def title @title end |
#x_axis_type ⇒ Object
Returns the value of attribute x_axis_type.
3 4 5 |
# File 'lib/flex_chart.rb', line 3 def x_axis_type @x_axis_type end |
#x_label ⇒ Object
Returns the value of attribute x_label.
3 4 5 |
# File 'lib/flex_chart.rb', line 3 def x_label @x_label end |
#y_axis_type ⇒ Object
Returns the value of attribute y_axis_type.
3 4 5 |
# File 'lib/flex_chart.rb', line 3 def y_axis_type @y_axis_type end |
#y_label ⇒ Object
Returns the value of attribute y_label.
3 4 5 |
# File 'lib/flex_chart.rb', line 3 def y_label @y_label end |
Instance Method Details
#fix_color(color) ⇒ Object
11 12 13 14 15 16 |
# File 'lib/flex_chart.rb', line 11 def fix_color(color) c = color.sub("#", "") newstr = "" c.each_char {|char| newstr << "#{char}0" } "0x" + newstr end |
#to_xml ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/flex_chart.rb', line 18 def to_xml xml = Builder::XmlMarkup.new xml.graph do xml.title(@title) xml.x_label(@x_label) xml.y_label(@y_label) xml.x_axis_type(@x_axis_type) xml.y_axis_type(@y_axis_type) xml.color(fix_color(@color)) xml.fill_color(fix_color(@fill_color)) xml.chart_type(self.class.to_s.split("::")[1]) series.each do |item| xml.graph_item do xml.title(item.title) xml.color(fix_color(item.color)) xml.dataset do item.values.each do |data| xml.data do xml.x_value(data[:x_value].strftime("%m/%d/%Y")) xml.y_value(data[:y_value]) end end end end end end end |