Module: Anychart::XML::ColumnBar

Defined in:
lib/column_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  =>  "{%Value}{numDecimals:0}",
    :x  =>  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



56
57
58
59
60
61
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
# File 'lib/column_bar.rb', line 56

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 => "CategorizedVertical") {
          xml.data_plot_settings(:default_series_type => "Bar") {
            xml.bar_series(:point_padding => "0.2", :group_padding => "1") {
              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]
                  xml.y_axis {
                    xml.labels {
                      xml.format p[:chart][:axes][:y]
                    }
                  }
                end
                
                if p[:chart][:axes][:x]
                  xml.y_axis {
                    xml.labels {
                      xml.format p[:chart][:axes][:x]
                    }
                  }
                end
              end
            }
          }

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

            series.each do |serie|
              xml.series(:name => serie[:name], :palette => "Default") {
                # Os varios pontos
                serie[:points].each do |point|
                  xml.point(:name => point[:name].to_s, :y => point[:value].to_s)
                end
              }
            end
          }
        }
      }
    }
  end
  builder.to_xml.gsub(/>[ \t\r\n]+</, '><')
end