Class: FlexChart::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/flex_chart.rb

Direct Known Subclasses

Area, Line, Pie

Instance Attribute Summary collapse

Instance Method Summary collapse

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(options = {})
  @series = []
  @x_axis_type = "Linear"
  @y_axis_type = "Linear"
end

Instance Attribute Details

#colorObject

Returns the value of attribute color.



3
4
5
# File 'lib/flex_chart.rb', line 3

def color
  @color
end

#fill_colorObject

Returns the value of attribute fill_color.



3
4
5
# File 'lib/flex_chart.rb', line 3

def fill_color
  @fill_color
end

#seriesObject

Returns the value of attribute series.



3
4
5
# File 'lib/flex_chart.rb', line 3

def series
  @series
end

#titleObject

Returns the value of attribute title.



3
4
5
# File 'lib/flex_chart.rb', line 3

def title
  @title
end

#x_axis_typeObject

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_labelObject

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_typeObject

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_labelObject

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_xmlObject



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