Class: ReportEngine::HorizontalChart

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

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ HorizontalChart

Returns a new instance of HorizontalChart.



7
8
9
10
11
# File 'lib/report_engine/horizontal_chart.rb', line 7

def initialize(options)
  @reference = options[:reference]
  @labels = options[:labels]
  @values = options[:values]
end

Instance Method Details

#generate_urlObject



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/report_engine/horizontal_chart.rb', line 13

def generate_url
  chart = GChart.bar do |g|
    g.colors = ['3A94EE']
    g.width  = 600
    g.height = 160
    g.max = 100
    g.data = @values
    g.orientation = :horizontal
     g.axis(:left) do |a|
        a.labels = @labels
        a.text_color = :black
      end
    g.axis(:bottom) do |a|
      a.labels = [0, 100]
      a.label_positions = [0,100]
      a.text_color = :black
    end
    if @reference
      g.axis(:bottom) do |a|
        a.labels = [@reference]
        a.label_positions = [@reference]
        a.text_color = :red
      end
    end
    g.extras = {"chm" => "#{"h,FF0000,0,#{@reference/100.0},1|" if @reference}N,000000,0,-1,11"}
  end
  chart.to_url
end