Method: Gruff::Scatter#data

Defined in:
lib/gruff/scatter.rb

#data(name, x_data_points = [], y_data_points = [], color = nil) ⇒ Object Also known as: dataxy

Note:

If you want to use a preset theme, you must set it before calling #data.

The first parameter is the name of the dataset. The next two are the x and y axis data points contain in their own array in that respective order. The final parameter is the color.

Can be called multiple times with different datasets for a multi-valued graph.

If the color argument is nil, the next color from the default theme will be used.

Examples:

g = Gruff::Scatter.new
g.data(:apples, [1,2,3], [3,2,1])
g.data('oranges', [1,1,1], [2,3,4])
g.data('bitter_melon', [3,5,6], [6,7,8], '#000000')

Parameters:

  • name (String, Symbol)

    containing the name of the dataset.

  • x_data_points (Array) (defaults to: [])

    An Array of of x-axis data points.

  • y_data_points (Array) (defaults to: [])

    An Array of of y-axis data points.

  • color (String) (defaults to: nil)

    The hex string for the color of the dataset. Defaults to nil.

Raises:

  • (ArgumentError)

    Data points contain nil values. This error will get raised if either the x or y axis data points array contains a nil value. The graph will not make an assumption as how to graph nil.

  • (ArgumentError)

    x_data_points is empty. This error is raised when the array for the x-axis points are empty

  • (ArgumentError)

    y_data_points is empty. This error is raised when the array for the y-axis points are empty.

  • (ArgumentError)

    x_data_points.length != y_data_points.length. Error means that the x and y axis point arrays do not match in length.



122
123
124
125
126
127
128
129
130
131
132
133
134
# File 'lib/gruff/scatter.rb', line 122

def data(name, x_data_points = [], y_data_points = [], color = nil)
  # make sure it's an array
  x_data_points = Array(x_data_points)
  y_data_points = Array(y_data_points)

  raise ArgumentError, 'Data Points contain nil Value!' if x_data_points.include?(nil) || y_data_points.include?(nil)
  raise ArgumentError, 'x_data_points is empty!' if x_data_points.empty?
  raise ArgumentError, 'y_data_points is empty!' if y_data_points.empty?
  raise ArgumentError, 'x_data_points.length != y_data_points.length!' if x_data_points.length != y_data_points.length

  # Call the existing data routine for the x/y axis data
  store.add(name, y_data_points, color, x_data_points)
end