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
# 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?
                Anychart::XML.axis(xml,p,:y,{ :y_axis_opposite => true }) # y axis
                Anychart::XML.axis(xml,p,:x) # x axis
              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