Class: ReportEngine::GoogleChart
- Inherits:
-
Object
- Object
- ReportEngine::GoogleChart
- Defined in:
- lib/report_engine/google_chart.rb
Direct Known Subclasses
Instance Method Summary collapse
- #generate_url ⇒ Object
-
#initialize(canvas, options) ⇒ GoogleChart
constructor
A new instance of GoogleChart.
- #max_value ⇒ Object
Constructor Details
#initialize(canvas, options) ⇒ GoogleChart
Returns a new instance of GoogleChart.
6 7 8 9 10 11 12 13 14 15 |
# File 'lib/report_engine/google_chart.rb', line 6 def initialize(canvas, ) @canvas = canvas @data = [:data] @scale_labels = [:scale_labels] @x_label = [:x_label] @y_label = [:y_label] @grouped = [:grouped].nil? ? true : [:grouped] @colors = [:colors] || ['97172E','EE8C9E'] @show_marker = [:show_marker] end |
Instance Method Details
#generate_url ⇒ Object
17 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 45 46 47 48 49 50 51 52 |
# File 'lib/report_engine/google_chart.rb', line 17 def generate_url max = @data.max chart = ::GChart. do |g| g.grouped = @grouped g.data = @data #values.map{|v| v * 100.0 / max } g.colors = @colors g.width = 520 g.height = 140 g.orientation = :vertical g.axis(:left) do |a| a.labels = [@y_label] #["%"] a.label_positions = [100] a.text_color = :black end g.axis(:bottom) do |a| a.labels = @scale_labels # ["0-10","10-20","20-30","30-40","40-50","50-60","60-70","70-80","80-90","90-100"] a.text_color = :black end g.axis(:bottom) do |a| a.labels = [@x_label] # ["Procentil"] a.label_positions = [100] a.text_color = :black end extra = {"chbh" => "a,5,10", "chds" => "0,#{max_value}"} extra.update("chbh" => "r,5,10") if @data.flatten.size < 3 if @show_marker if @data.first.is_a? Array extra.update("chm" => @data.size.times.map{|i| "N,000000,#{i},-1,11" }.join('|')) else extra.update("chm" => "N,000000,0,-1,11") end end g.extras = extra end chart.to_url end |
#max_value ⇒ Object
54 55 56 |
# File 'lib/report_engine/google_chart.rb', line 54 def max_value @data.flatten.max end |