Class | Gruff::Line |
In: |
lib/gruff/line.rb
|
Parent: | Gruff::Base |
Here‘s how to make a Line graph:
g = Gruff::Line.new g.title = "A Line Graph" g.data 'Fries', [20, 23, 19, 8] g.data 'Hamburgers', [50, 19, 99, 29] g.write("test/output/line.png")
There are also other options described below, such as baseline_value, baseline_color, hide_dots, and hide_lines.
dot_radius | [RW] | |
hide_dots | [RW] | Hide parts of the graph to fit more datapoints, or for a different appearance. |
hide_lines | [RW] | Hide parts of the graph to fit more datapoints, or for a different appearance. |
line_width | [RW] | Dimensions of lines and dots; calculated based on dataset size if left unspecified |
maximum_x_value | [RW] | |
minimum_x_value | [RW] | accessors for support of xy data |
reference_line_default_color | [RW] | |
reference_line_default_width | [RW] | |
reference_lines | [RW] | Allow for reference lines ( which are like baseline … just allowing for more & on both axes ) |
show_vertical_markers | [RW] | Allow for vertical marker lines |
Call with target pixel width of graph (800, 400, 300), and/or ‘false’ to omit lines (points only).
g = Gruff::Line.new(400) # 400px wide with lines g = Gruff::Line.new(400, false) # 400px wide, no lines (for backwards compatibility) g = Gruff::Line.new(false) # Defaults to 800px wide, no lines (for backwards compatibility)
The preferred way is to call hide_dots or hide_lines instead.
This method allows one to plot a dataset with both X and Y data.
Parameters are as follows:
name: string, the title of the dataset x_data_points: an array containing the x data points for the graph y_data_points: an array containing the y data points for the graph color: hex number indicating the line color as an RGB triplet or name: string, the title of the dataset xy_data_points: an array containing both x and y data points for the graph color: hex number indicating the line color as an RGB triplet Notes: -if (x_data_points.length != y_data_points.length) an error is returned. -if the color argument is nil, the next color from the default theme will be used. -if you want to use a preset theme, you must set it before calling dataxy().
Example:
g = Gruff::Line.new g.title = "X/Y Dataset" g.dataxy("Apples", [1,3,4,5,6,10], [1, 2, 3, 4, 4, 3]) g.dataxy("Bapples", [1,3,4,5,7,9], [1, 1, 2, 2, 3, 3]) g.dataxy("Capples", [[1,1],[2,3],[3,4],[4,5],[5,7],[6,9]]) #you can still use the old data method too if you want: g.data("Capples", [1, 1, 2, 2, 3, 3]) #labels will be drawn at the x locations of the keys passed in. In this example the lables are drawn at x positions 2, 4, and 6: g.labels = {0 => '2003', 2 => '2004', 4 => '2005', 6 => '2006'} The 0 => '2003' label will be ignored since it is outside the chart range.