Class: Gruff::Histogram

Inherits:
Bar show all
Defined in:
lib/gruff/histogram.rb

Overview

Here’s how to set up a Gruff::Histogram.

g = Gruff::Histogram.new
g.title = 'Histogram Graph'
g.minimum_bin = 10
g.bin_width = 20
g.data :A, [10, 10, 20, 30, 40, 40, 40, 40, 40, 40, 50, 10, 10, 10]
g.data :B, [100, 100, 100, 100, 90, 90, 80, 30, 30, 30, 30, 30]
g.write('histogram.png')

Constant Summary

Constants inherited from Base

Base::DEFAULT_MARGIN, Base::DEFAULT_TARGET_WIDTH, Base::LABEL_MARGIN, Base::LEGEND_MARGIN

Instance Attribute Summary

Attributes inherited from Bar

#bar_spacing, #group_spacing, #label_formatting, #show_labels_for_bar_values

Attributes inherited from Base

#bold_title, #bottom_margin, #center_labels_over_point, #colors, #font, #font_color, #has_left_labels, #hide_legend, #hide_line_markers, #hide_line_numbers, #hide_title, #label_max_size, #label_stagger_height, #label_truncation_style, #labels, #left_margin, #legend_at_bottom, #legend_box_size, #legend_font_size, #legend_margin, #marker_color, #marker_count, #marker_font_size, #marker_shadow_color, #maximum_value, #minimum_value, #no_data_message, #right_margin, #sort, #sorted_drawing, #title, #title_font, #title_font_size, #title_margin, #top_margin, #use_data_label, #x_axis_increment, #x_axis_label, #y_axis_increment, #y_axis_label

Instance Method Summary collapse

Methods inherited from Bar

#draw, #spacing_factor=

Methods inherited from Base

#add_color, #initialize, #margins=, #replace_colors, #theme=, #theme_37signals, #theme_greyscale, #theme_keynote, #theme_odeo, #theme_pastel, #theme_rails_keynote, #to_blob, #write

Constructor Details

This class inherits a constructor from Gruff::Base

Instance Method Details

#bin_width=(width) ⇒ Object

Specifies interpolation between the min and max of the set. Default is 10.



27
28
29
30
31
# File 'lib/gruff/histogram.rb', line 27

def bin_width=(width)
  raise 'bin_width= should be called before set the data.' unless store.empty?

  @bin_width = width
end

#data(name, data_points = [], color = nil) ⇒ Object



47
48
49
50
51
52
53
# File 'lib/gruff/histogram.rb', line 47

def data(name, data_points = [], color = nil)
  bins, freqs = HistogramArray.new(data_points).histogram(bin_width: @bin_width, min: @minimum_bin, max: @maximum_bin)
  bins.each_with_index do |bin, index|
    labels[index] = bin
  end
  store.add(name, freqs, color)
end

#maximum_bin=(max) ⇒ Object

Specifies maximum value for bin.



41
42
43
44
45
# File 'lib/gruff/histogram.rb', line 41

def maximum_bin=(max)
  raise 'maximum_bin= should be called before set the data.' unless store.empty?

  @maximum_bin = max
end

#minimum_bin=(min) ⇒ Object

Specifies minimum value for bin.



34
35
36
37
38
# File 'lib/gruff/histogram.rb', line 34

def minimum_bin=(min)
  raise 'minimum_bin= should be called before set the data.' unless store.empty?

  @minimum_bin = min
end