Module: Anychart::XML::LineBar

Defined in:
lib/line_bar.rb

Constant Summary collapse

@@default_xml_options =

Options

:tooltip => “%Name - %YValue”,

   :chart   => {
     :title   => "Multi-Series: with Simple Legend",
     :legend  => {
       :format => "{%Icon} {%Name} ({%Value})",
       :position => "Bottom",
       :title => "lalala"
     },
     :axes    => {
       :y =>  "{%Value}{numDecimals:0}"
     }
},
:data    => {
  :series => [
    {:name => "Series 1",
      :points  => [ {:name  => "P1", :value => "12"},
        {:name  => "P2", :value => "24"}
      ]
      },
      {:name => "Series 2",
        :points  => [ {:name  => "P1", :value => "23"},
          {:name  => "P2", :value => "45"}
        ]
      }
    ]
 }
{
  :animation    => true,
  :tooltip      => false, # "{%Name} - {%YValue}"
  :chart        => {
    :title        => false,
    :legend       => false,
    :axes         => {
      :y  =>  {
        :title => "Tit Ax Y",
        :format => "{%Value}{numDecimals:0}"
      },
      :x  =>  {
        :title => false
      }
    },
    :data => {
      :series => [
        {
          :name => "Serie de omissao",
          :points => [{:name => "X1", :value => "1"},{:name => "X2", :value => "2"}]    
        }
      ]
    }
  }
}

Class Method Summary collapse

Class Method Details

.xml(options = {}) ⇒ Object



62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
# File 'lib/line_bar.rb', line 62

def self.xml(options={})
  p = @@default_xml_options.merge(options)

  builder = Nokogiri::XML::Builder.new do |xml|
    xml.anychart {
      xml.settings {
        xml.animation(:enabled => "True") if p[:animation]
      }
      xml.charts {
        xml.chart(:plot_type => "CategorizedHorizontal") {
          xml.data_plot_settings(:default_series_type => "Bar") {
            xml.bar_series(:group_padding => "0.7", :style => "AquaLight") {
              if p[:tooltip]
                xml.tooltip_settings(:enabled => "True") {
                  xml.format p[:tooltip]
                }
              else
                xml.tooltip_settings(:enabled => "False") {}
              end
            }
          }

          xml.chart_settings {
            Anychart::XML.chart_background(xml,p) # background
            Anychart::XML.chart_title(xml,p) # title
            Anychart::XML.legend(xml,p) # legend

            xml.axes {
              if p[:chart][:axes].present?
                if p[:chart][:axes][:y].present?
                  xml.y_axis(:position => "Opposite") {
                    if p[:chart][:axes][:y][:scale].present?
                      xml.scale(p[:chart][:axes][:y][:scale])
                    end
                    if p[:chart][:axes][:y][:title].present?
                      xml.title {
                        xml.text_ p[:chart][:axes][:y][:title]
                      }
                    else
                      xml.title(:enabled => "false")
                    end
                    xml.labels(:align => "Inside") {
                      xml.format p[:chart][:axes][:y][:format] || "{%Value}"
                    }
                  }
                end
                
                if p[:chart][:axes][:x]
                  xml.x_axis {
                    if p[:chart][:axes][:x][:title].present?
                      xml.title {
                        xml.text_ p[:chart][:axes][:x][:title]
                      }
                    else
                      xml.title(:enabled => "false")
                    end
                  }
                end
              end
            }
          }

          xml.data {
            series = (p[:data][:series].kind_of?(Array) ? p[:data][:series] : [p[:data][:series]])

            series.each_with_index do |serie,serie_idx|
              xml.series(:name => (serie[:name].blank? ? "Series #{serie_idx + 1}" : serie[:name]), :palette => "Default") {
                # Os varios pontos
                serie[:points].each do |point|
                  h = {:name => point[:name].to_s, :y => point[:value].to_s}
                  h.merge!({:color => point[:color].to_s}) if point[:color].present?
                  xml.point(h)
                end
              }
            end
          }
        }
      }
    }
  end
  builder.to_xml.gsub(/>[ \t\r\n]+</, '><')
end