gregoryfoster-gchartrb 0.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/CREDITS +6 -0
- data/History.txt +69 -0
- data/Manifest.txt +47 -0
- data/README.txt +64 -0
- data/Rakefile +61 -0
- data/TODO +10 -0
- data/gchartrb.gemspec +18 -0
- data/lib/core_ext.rb +32 -0
- data/lib/example.rb +75 -0
- data/lib/gchartrb.rb +1 -0
- data/lib/google_chart.rb +39 -0
- data/lib/google_chart/bar_chart.rb +83 -0
- data/lib/google_chart/base.rb +148 -0
- data/lib/google_chart/line_chart.rb +19 -0
- data/lib/google_chart/linexy_chart.rb +20 -0
- data/lib/google_chart/map_chart.rb +74 -0
- data/lib/google_chart/modules/axis.rb +62 -0
- data/lib/google_chart/modules/color.rb +15 -0
- data/lib/google_chart/modules/data_array.rb +57 -0
- data/lib/google_chart/modules/fills.rb +102 -0
- data/lib/google_chart/modules/grid.rb +27 -0
- data/lib/google_chart/modules/label.rb +27 -0
- data/lib/google_chart/modules/legend.rb +24 -0
- data/lib/google_chart/modules/markers.rb +88 -0
- data/lib/google_chart/pie_chart.rb +44 -0
- data/lib/google_chart/radar_chart.rb +33 -0
- data/lib/google_chart/scatter_plot.rb +34 -0
- data/lib/google_chart/sparkline_chart.rb +19 -0
- data/lib/google_chart/venn_diagram.rb +41 -0
- data/lib/test.rb +252 -0
- data/scripts/iso3166_en_code_lists.txt +250 -0
- data/scripts/process_country_codes.rb +27 -0
- data/spec/gchartrb/axis_spec.rb +125 -0
- data/spec/gchartrb/bar_chart_spec.rb +128 -0
- data/spec/gchartrb/fills_spec.rb +124 -0
- data/spec/gchartrb/grid_spec.rb +59 -0
- data/spec/gchartrb/line_chart_spec.rb +78 -0
- data/spec/gchartrb/linexy_chart_spec.rb +31 -0
- data/spec/gchartrb/markers_spec.rb +160 -0
- data/spec/gchartrb/pie_chart_spec.rb +36 -0
- data/spec/gchartrb/radar_chart_spec.rb +40 -0
- data/spec/gchartrb/scatter_plot_spec.rb +37 -0
- data/spec/gchartrb/sparkline_chart_spec.rb +16 -0
- data/spec/gchartrb/venn_diagram_spec.rb +57 -0
- data/spec/gchartrb_spec.rb +117 -0
- data/spec/helper.rb +15 -0
- data/spec/spec.opts +7 -0
- metadata +102 -0
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
require 'ostruct'
|
|
2
|
+
module GoogleChart
|
|
3
|
+
# This module is used as a mixin for providing grid functionality
|
|
4
|
+
module Grid
|
|
5
|
+
GridLines = Struct.new("GridLines", :x_step, :y_step, :line_segment, :blank_segment)
|
|
6
|
+
def grid(options={})
|
|
7
|
+
grid_lines = GridLines.new
|
|
8
|
+
grid_lines.blank_segment = 0
|
|
9
|
+
options.each { |k,v| grid_lines.send("#{k}=",v) }
|
|
10
|
+
yield grid_lines if block_given?
|
|
11
|
+
|
|
12
|
+
validate_grid(grid_lines)
|
|
13
|
+
@grid = grid_lines
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
private
|
|
17
|
+
def add_grid
|
|
18
|
+
[:x_step, :y_step, :line_segment, :blank_segment].collect { |m| @grid.send(m)}.compact.join(",")
|
|
19
|
+
@params[:chg] = [:x_step, :y_step, :line_segment, :blank_segment].collect { |m| @grid.send(m) }.compact.join(",")
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def validate_grid(grid)
|
|
23
|
+
[:x_step, :y_step, :line_segment, :blank_segment].each { |m| raise ArgumentError.new("all properties of grid must be numeric") unless grid.send(m).is_a?(Numeric) }
|
|
24
|
+
raise ArgumentError.new("x_step and y_step must be within 0 to 100") unless (1..100).include?(grid.x_step) and (1..100).include?(grid.y_step)
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
end
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
module GoogleChart
|
|
2
|
+
# This module is used as a mixin for providing legend functionality
|
|
3
|
+
module Label
|
|
4
|
+
def self.included(mod)
|
|
5
|
+
mod.class_eval do
|
|
6
|
+
attr_accessor :show_labels
|
|
7
|
+
|
|
8
|
+
def show_labels?
|
|
9
|
+
@show_labels
|
|
10
|
+
end
|
|
11
|
+
end
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
private
|
|
16
|
+
def label(label)
|
|
17
|
+
@labels ||= []
|
|
18
|
+
@labels << label
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def add_labels
|
|
22
|
+
@params[:chl] = @labels.join("|") unless @labels.empty?
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
module GoogleChart
|
|
2
|
+
# This module is used as a mixin for providing legend functionality
|
|
3
|
+
module Legend
|
|
4
|
+
def self.included(mod)
|
|
5
|
+
mod.class_eval do
|
|
6
|
+
attr_accessor :show_legend
|
|
7
|
+
|
|
8
|
+
def show_legend?
|
|
9
|
+
@show_legend
|
|
10
|
+
end
|
|
11
|
+
end
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
private
|
|
15
|
+
def legend(legend)
|
|
16
|
+
@legends ||= []
|
|
17
|
+
@legends << legend
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def add_legends
|
|
21
|
+
@params[:chdl] = @legends.join("|") unless @legends.empty?
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
end
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
require 'ostruct'
|
|
2
|
+
module GoogleChart
|
|
3
|
+
# This module is used as a mixin for providing shape markers, and horizontal and vertical range markers
|
|
4
|
+
module Markers
|
|
5
|
+
ORIENTATION = {:horizontal => "r", :vertical => "R" }
|
|
6
|
+
|
|
7
|
+
SHAPES = {
|
|
8
|
+
:arrow => "a",
|
|
9
|
+
:cross => "c",
|
|
10
|
+
:diamond => "d",
|
|
11
|
+
:circle => "o",
|
|
12
|
+
:square => "s",
|
|
13
|
+
:text => "t",
|
|
14
|
+
:vertical_line_top => "v",
|
|
15
|
+
:vertical_line_bottom => "V",
|
|
16
|
+
:horizontal_line => "h",
|
|
17
|
+
:x => "x"
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
PRIORITY = { :high => 1, :low => -1 }
|
|
21
|
+
|
|
22
|
+
RangeMarker = Struct.new("RangeMarker", :orientation, :color, :start, :end)
|
|
23
|
+
ShapeMarker = Struct.new("ShapeMarker", :shape, :color, :data_set, :data_point, :size, :priority, :text)
|
|
24
|
+
|
|
25
|
+
def shape_marker(shape, options={})
|
|
26
|
+
@markers ||= []
|
|
27
|
+
marker = ShapeMarker.new
|
|
28
|
+
marker.shape = shape
|
|
29
|
+
|
|
30
|
+
options.each { |k,v| marker.send("#{k}=",v) }
|
|
31
|
+
yield marker if block_given?
|
|
32
|
+
|
|
33
|
+
validate_shape_marker(marker)
|
|
34
|
+
values = [:shape, :color, :data_set, :data_point, :size, :priority].collect { |m| marker.send(m) }.compact
|
|
35
|
+
values[0] = SHAPES[marker.shape]
|
|
36
|
+
values[0] += (marker.text.gsub(" ","+")) if marker.shape == :text
|
|
37
|
+
values[5] = PRIORITY[marker.priority] if values[5]
|
|
38
|
+
@markers << values.join(",")
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
def range_marker(orientation, options={})
|
|
42
|
+
@markers ||= []
|
|
43
|
+
marker = RangeMarker.new
|
|
44
|
+
marker.orientation = orientation
|
|
45
|
+
|
|
46
|
+
options.each { |k,v| marker.send("#{k}=",v) }
|
|
47
|
+
yield marker if block_given?
|
|
48
|
+
|
|
49
|
+
validate_range_marker(marker)
|
|
50
|
+
|
|
51
|
+
values = [:orientation, :color, :start, :end].collect { |m| marker.send(m) }
|
|
52
|
+
values[0] = ORIENTATION[marker.orientation]
|
|
53
|
+
values.insert 2, "0"
|
|
54
|
+
@markers << values.join(",")
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
private
|
|
58
|
+
def add_markers
|
|
59
|
+
@params[:chm] = @markers.join("|")
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
def validate_range_marker(marker)
|
|
63
|
+
raise ArgumentError.new("Invalid orientation value. Must be one of :horizontal or :vertical") unless ORIENTATION.keys.include?(marker.orientation)
|
|
64
|
+
raise ArgumentError.new("start and end values must be numeric") unless marker.start.is_a?(Numeric) and marker.end.is_a?(Numeric)
|
|
65
|
+
raise ArgumentError.new("start and end values must be within 0 and 1") unless (0..1).include?(marker.start) and (0..1).include?(marker.end)
|
|
66
|
+
raise ArgumentError.new("start value must be less than end value") unless marker.start < marker.end
|
|
67
|
+
raise ArgumentError.new("start value must be less than end value") unless marker.color.is_a?(String)
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
def validate_shape_marker(marker)
|
|
71
|
+
raise ArgumentError.new("Invalid shape") unless SHAPES.keys.include?(marker.shape)
|
|
72
|
+
raise ArgumentError.new("Invalid color. :color must be a string") unless marker.color.is_a?(String)
|
|
73
|
+
raise ArgumentError.new("Invalid data set value. Must be and integer less than #{@data.length}") unless marker.data_set.is_a?(Integer) and
|
|
74
|
+
marker.data_set < @data.length and
|
|
75
|
+
marker.data_set >= 0
|
|
76
|
+
|
|
77
|
+
raise ArgumentError.new("Invalid data set value. Must be and integer less than #{@data[marker.data_set].length}") unless marker.data_point.is_a?(Integer) and
|
|
78
|
+
marker.data_point < @data[marker.data_set].length and
|
|
79
|
+
marker.data_point >= 0
|
|
80
|
+
raise ArgumentError.new("Invalid priority. :priority must be either :low or :high") unless marker.priority == nil or
|
|
81
|
+
PRIORITY.keys.include?(marker.priority)
|
|
82
|
+
|
|
83
|
+
raise ArgumentError.new("Size must be an integer") unless marker.size.is_a?(Integer)
|
|
84
|
+
raise ArgumentError.new("Text should not be specified if marker is not text") if marker.text and marker.shape != :text
|
|
85
|
+
raise ArgumentError.new("Text should be specified (using :text) if marker is text") if marker.text == nil and marker.shape == :text
|
|
86
|
+
end
|
|
87
|
+
end
|
|
88
|
+
end
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
module GoogleChart
|
|
2
|
+
class PieChart < Base
|
|
3
|
+
include Fills
|
|
4
|
+
include Color
|
|
5
|
+
include DataArray
|
|
6
|
+
include Label
|
|
7
|
+
|
|
8
|
+
data_type :numeric
|
|
9
|
+
|
|
10
|
+
attr_accessor :is_3d
|
|
11
|
+
|
|
12
|
+
def initialize(options={})
|
|
13
|
+
@is_3d = false
|
|
14
|
+
set_chart_type
|
|
15
|
+
@label ||=
|
|
16
|
+
@show_labels = true
|
|
17
|
+
super(options)
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def is_3d=(three_d)
|
|
21
|
+
@is_3d = three_d
|
|
22
|
+
set_chart_type
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def is_3d?
|
|
26
|
+
self.is_3d
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
def set_chart_type
|
|
30
|
+
if is_3d?
|
|
31
|
+
@chart_type = "p3"
|
|
32
|
+
else
|
|
33
|
+
@chart_type = "p"
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
def data(label,data,color=nil)
|
|
38
|
+
raise ArgumentError.new("data should be an integer value") unless data.is_a?(Numeric)
|
|
39
|
+
@data << data
|
|
40
|
+
label(label)
|
|
41
|
+
color(color)
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
end
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
module GoogleChart
|
|
2
|
+
class RadarChart < Base
|
|
3
|
+
include Legend
|
|
4
|
+
include Color
|
|
5
|
+
include DataArray
|
|
6
|
+
include Fills
|
|
7
|
+
include Axis
|
|
8
|
+
include Grid
|
|
9
|
+
include Markers
|
|
10
|
+
|
|
11
|
+
data_type :numeric_array
|
|
12
|
+
|
|
13
|
+
# Indicates if the data points should be connected by splines
|
|
14
|
+
attr_accessor :splines
|
|
15
|
+
|
|
16
|
+
def initialize(options={}) #:nodoc:
|
|
17
|
+
@splines = false
|
|
18
|
+
set_chart_type
|
|
19
|
+
@show_legend = false
|
|
20
|
+
super(options)
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def set_chart_type
|
|
24
|
+
if @splines then @chart_type = "rs" ; else @chart_type = "r" ; end
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def splines=(connect_with_splines)
|
|
28
|
+
raise ArgumentError.new("splines must be a boolean value") unless [true, false].include?(connect_with_splines)
|
|
29
|
+
@splines = connect_with_splines
|
|
30
|
+
set_chart_type
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
end
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
module GoogleChart
|
|
2
|
+
class ScatterPlot < Base
|
|
3
|
+
include Legend
|
|
4
|
+
include Color
|
|
5
|
+
include DataArray
|
|
6
|
+
include Fills
|
|
7
|
+
include Axis
|
|
8
|
+
include Grid
|
|
9
|
+
include Markers
|
|
10
|
+
|
|
11
|
+
data_type :numeric_2d_array
|
|
12
|
+
|
|
13
|
+
def initialize(options={})
|
|
14
|
+
@chart_type = "s"
|
|
15
|
+
@show_legend = false
|
|
16
|
+
super(options)
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def point_sizes(values)
|
|
20
|
+
raise ArgumentError.new("point sizes should be an array") unless values.is_a?(Array)
|
|
21
|
+
raise ArgumentError.new("All values for point size must be integers") unless values.is_numeric_array?
|
|
22
|
+
raise ArgumentError.new("Point size array must not be bigger than the dataset size") unless @data.first.length == values.length
|
|
23
|
+
@point_sizes = values
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
private
|
|
27
|
+
def encode_data
|
|
28
|
+
sets = super
|
|
29
|
+
unless @point_sizes.empty?
|
|
30
|
+
sets << @point_sizes.collect { |d| GoogleChart::encode(encoding,d,@point_sizes.max) }.join(get_data_separator)
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
end
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
module GoogleChart
|
|
2
|
+
class SparklineChart < Base
|
|
3
|
+
include Legend
|
|
4
|
+
include Color
|
|
5
|
+
include DataArray
|
|
6
|
+
include Fills
|
|
7
|
+
include Axis
|
|
8
|
+
include Grid
|
|
9
|
+
include Markers
|
|
10
|
+
|
|
11
|
+
data_type :numeric_array
|
|
12
|
+
|
|
13
|
+
def initialize(options={}) #:nodoc:
|
|
14
|
+
@chart_type = "ls"
|
|
15
|
+
@show_legend = false
|
|
16
|
+
super(options)
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
end
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
module GoogleChart
|
|
2
|
+
|
|
3
|
+
class VennDiagram < Base
|
|
4
|
+
include Legend
|
|
5
|
+
include Fills
|
|
6
|
+
include Color
|
|
7
|
+
include DataArray
|
|
8
|
+
|
|
9
|
+
data_type :numeric
|
|
10
|
+
|
|
11
|
+
def initialize(options={})
|
|
12
|
+
@chart_type="v"
|
|
13
|
+
@show_legend = false
|
|
14
|
+
@intersections = []
|
|
15
|
+
super(options)
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
# Specify the intersections of the circles in the Venn Diagram. See the Rdoc for class for sample
|
|
19
|
+
def intersections(*values)
|
|
20
|
+
raise ArgumentError.new("Please intialise the data first before adding intersections") if @data.empty?
|
|
21
|
+
raise ArgumentError.new("You can have at most three intersections") if values.size > 4
|
|
22
|
+
raise ArgumentError.new("You cannot have more intersections than data points") if values.size > (@data.size + 1)
|
|
23
|
+
raise ArgumentError.new("all values must be integers") unless values.all? { |v| v.is_a?(Integer) }
|
|
24
|
+
@intersections = values
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def data(legend, data, color = nil)
|
|
28
|
+
raise ArgumentError.new("data should be an integer value") unless data.is_a?(Integer)
|
|
29
|
+
raise ArgumentError.new("you can only insert upto 3 data points") if @data.size == 3
|
|
30
|
+
@data << data
|
|
31
|
+
legend(legend)
|
|
32
|
+
color(color)
|
|
33
|
+
end
|
|
34
|
+
private
|
|
35
|
+
def encode_data
|
|
36
|
+
@data.push(0) until @data.size == 3
|
|
37
|
+
@data = @data + @intersections unless @intersections.empty?
|
|
38
|
+
super
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
end
|
data/lib/test.rb
ADDED
|
@@ -0,0 +1,252 @@
|
|
|
1
|
+
require 'gchartrb'
|
|
2
|
+
=begin
|
|
3
|
+
# Pie Chart
|
|
4
|
+
GoogleChart::PieChart.new do |pc|
|
|
5
|
+
pc.data "Apples", 40
|
|
6
|
+
pc.data "Banana", 20
|
|
7
|
+
pc.data "Peach", 30
|
|
8
|
+
pc.data "Orange", 60
|
|
9
|
+
|
|
10
|
+
puts "\nPie Chart"
|
|
11
|
+
puts pc.to_url
|
|
12
|
+
|
|
13
|
+
pc.show_labels = false
|
|
14
|
+
puts "\nPie Chart (with no labels)"
|
|
15
|
+
puts pc.to_url
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
# Line Chart
|
|
19
|
+
GoogleChart::LineChart.new do |lc|
|
|
20
|
+
lc.title = "Line Chart"
|
|
21
|
+
lc.show_legend = true
|
|
22
|
+
|
|
23
|
+
lc.data "Trend 1", [5,4,3,1,3,5,6], '0000ff'
|
|
24
|
+
lc.data "Trend 2", [1,2,3,4,5,6], '00ff00'
|
|
25
|
+
lc.data "Trend 3", [6,5,4,3,2,1], 'ff0000'
|
|
26
|
+
|
|
27
|
+
lc.axis(:left) do |axis|
|
|
28
|
+
axis.alignment = :center
|
|
29
|
+
axis.color = "ff00ff"
|
|
30
|
+
axis.font_size = 16
|
|
31
|
+
axis.range = 0..6
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
lc.axis :bottom, :alignment => :center, :color => "ff00ff", :font_size => 16, :range => 0..6
|
|
35
|
+
lc.grid :x_step => 100.0/6.0, :y_step => 100.0/6.0, :line_segment => 1, :blank_segment => 0
|
|
36
|
+
|
|
37
|
+
puts "\nLine Chart"
|
|
38
|
+
puts lc.to_url
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
# Bar Chart
|
|
42
|
+
GoogleChart::BarChart.new do |bc|
|
|
43
|
+
bc.title = "Bar Chart"
|
|
44
|
+
bc.width = 800
|
|
45
|
+
bc.height = 200
|
|
46
|
+
bc.orientation = :vertical
|
|
47
|
+
bc.grouping = :grouped
|
|
48
|
+
|
|
49
|
+
bc.data "Trend 1", [5,4,3,1,3,5], '0000ff'
|
|
50
|
+
bc.data "Trend 2", [1,2,3,4,5,6], 'ff0000'
|
|
51
|
+
bc.data "Trend 3", [6,5,4,4,5,6], '00ff00'
|
|
52
|
+
|
|
53
|
+
bc.bar_width = 5
|
|
54
|
+
bc.bar_spacing = 2
|
|
55
|
+
bc.group_spacing = 10
|
|
56
|
+
|
|
57
|
+
bc.shape_marker :text, :text => "Test", :color => "000000" ,:data_set => 0, :data_point => 1, :size => 14
|
|
58
|
+
puts "\nBar Chart"
|
|
59
|
+
puts bc.to_url
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
# Line XY Chart
|
|
63
|
+
line_chart_xy = GoogleChart::LineXYChart.new do |lcxy|
|
|
64
|
+
lcxy.title = "Line XY Chart"
|
|
65
|
+
lcxy.show_legend = true
|
|
66
|
+
|
|
67
|
+
lcxy.data "Trend 1", [[1,1], [2,2], [3,3], [4,4]], '0000ff'
|
|
68
|
+
lcxy.data "Trend 2", [[4,5], [2,2], [1,1], [3,4]], '00ff00'
|
|
69
|
+
puts "\nLine XY Chart (inside a block)"
|
|
70
|
+
|
|
71
|
+
puts lcxy.to_url
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
# Venn Diagram
|
|
75
|
+
GoogleChart::VennDiagram.new(:title => 'Venn Diagram') do |vd|
|
|
76
|
+
vd.show_legend = true
|
|
77
|
+
|
|
78
|
+
vd.data "Blue", 100, '0000ff'
|
|
79
|
+
vd.data "Green", 80, '00ff00'
|
|
80
|
+
vd.data "Red", 60, 'ff0000'
|
|
81
|
+
|
|
82
|
+
vd.intersections 30,30,30,10
|
|
83
|
+
puts "\nVenn Diagram"
|
|
84
|
+
puts vd.to_url
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
# Scatter Plot
|
|
88
|
+
GoogleChart::ScatterPlot.new do |sc|
|
|
89
|
+
sc.title = "Scatter Chart"
|
|
90
|
+
sc.data "Scatter Set", [[1,1,], [2,2], [3,3], [4,4]]
|
|
91
|
+
sc.max_x = 5
|
|
92
|
+
sc.max_y = 5
|
|
93
|
+
sc.point_sizes [10,15,30,55]
|
|
94
|
+
|
|
95
|
+
sc.axis(:bottom, :range => 0..5)
|
|
96
|
+
sc.axis(:left, :range => 0..5, :labels => [0,1,2,3,4,5])
|
|
97
|
+
puts "\nScatter Chart"
|
|
98
|
+
puts sc.to_url
|
|
99
|
+
end
|
|
100
|
+
|
|
101
|
+
# Solid fill
|
|
102
|
+
line_chart_xy.fill :solid, :type => :background, :color => 'fff2cc'
|
|
103
|
+
line_chart_xy.fill(:solid, :type => :chart ,:color => 'ffcccc')
|
|
104
|
+
puts "\nLine Chart with Solid Fill"
|
|
105
|
+
puts line_chart_xy.to_url
|
|
106
|
+
|
|
107
|
+
# Gradient Fill
|
|
108
|
+
line_chart_xy.fill :gradient, :type => :background, :angle => 0, :colors => ['76A4FB','ffffff'], :offsets => [1,0]
|
|
109
|
+
line_chart_xy.fill :gradient, :type => :chart, :angle => 0, :colors => ['76A4FB','ffffff'], :offsets => [1,0]
|
|
110
|
+
puts "\nLine Chart with Gradient Fill"
|
|
111
|
+
puts line_chart_xy.to_url
|
|
112
|
+
|
|
113
|
+
# Stripes Fill
|
|
114
|
+
line_chart_xy.fill :stripes, :type => :chart, :angle => 90, :colors => ['76A4FB','ffffff'], :widths => [0.2,0.2]
|
|
115
|
+
puts "\nLine Chart with Stripes Fill"
|
|
116
|
+
puts line_chart_xy.to_url
|
|
117
|
+
|
|
118
|
+
# Range and Shape Markers
|
|
119
|
+
puts "\nLine Chart with range markers and shape markers"
|
|
120
|
+
GoogleChart::LineChart.new do |lc|
|
|
121
|
+
lc.title = "Line Chart"
|
|
122
|
+
lc.title_color = 'ff00ff'
|
|
123
|
+
lc.show_legend = true
|
|
124
|
+
|
|
125
|
+
lc.data "Trend 1", [5,4,3,1,3,5,6], '0000ff'
|
|
126
|
+
lc.data "Trend 2", [1,2,3,4,5,6], '00ff00'
|
|
127
|
+
lc.data "Trend 3", [6,5,4,3,2,1], 'ff0000'
|
|
128
|
+
lc.max = 10
|
|
129
|
+
|
|
130
|
+
lc.range_marker :horizontal, :color => 'E5ECF9', :start => 0.1, :end => 0.5
|
|
131
|
+
lc.range_marker :vertical, :color => 'a0bae9', :start => 0.1, :end => 0.5
|
|
132
|
+
|
|
133
|
+
# Draw an arrow shape marker against lowest value in dataset
|
|
134
|
+
lc.shape_marker :arrow, :color => '000000', :data_set => 0, :data_point => 3, :size => 10
|
|
135
|
+
puts lc.to_url
|
|
136
|
+
end
|
|
137
|
+
|
|
138
|
+
# Bryan Error condition
|
|
139
|
+
lcxy = GoogleChart::LineXYChart.new
|
|
140
|
+
lcxy.title = "Line Chart"
|
|
141
|
+
lcxy.show_legend = true
|
|
142
|
+
lcxy.data 'A', [[0, 32], [1, 15], [2, 23], [3, 18], [4, 41], [5, 53]],'0000ff'
|
|
143
|
+
lcxy.data 'B', [[0, 73], [1, 0], [2, 28], [3, 0], [4, 333], [5, 0]], '00ff00'
|
|
144
|
+
lcxy.data 'C', [[0, 22], [1, 26], [2, 14], [3, 33], [4, 17], [5, 7]], 'ff0000'
|
|
145
|
+
lcxy.data 'D', [[0, 4], [1, 39], [2, 0], [3, 5], [4, 11], [5, 14]], 'cc00ff'
|
|
146
|
+
puts "\nBryan Error Condition"
|
|
147
|
+
puts lcxy.to_url
|
|
148
|
+
|
|
149
|
+
# Stacked Chart error
|
|
150
|
+
stacked = GoogleChart::BarChart.new
|
|
151
|
+
|
|
152
|
+
stacked.title = "Stacked Chart"
|
|
153
|
+
stacked.title_color='ff0000'
|
|
154
|
+
stacked.title_font_size=18
|
|
155
|
+
stacked.orientation = :vertical
|
|
156
|
+
stacked.grouping = :stacked
|
|
157
|
+
stacked.encoding = :text
|
|
158
|
+
|
|
159
|
+
stacked.data "Trend 1", [60,80,20], '0000ff'
|
|
160
|
+
stacked.data "Trend 2", [50,5,100], 'ff0000'
|
|
161
|
+
stacked.axis :left, :range => 0..120
|
|
162
|
+
puts "\nStacked Chart with colored title"
|
|
163
|
+
puts stacked.to_url
|
|
164
|
+
|
|
165
|
+
# Encoding Error (Bar Chart)
|
|
166
|
+
bc = GoogleChart::BarChart.new do |chart|
|
|
167
|
+
chart.width = 800
|
|
168
|
+
chart.height = 350
|
|
169
|
+
chart.orientation = :vertical
|
|
170
|
+
chart.grouping = :stacked
|
|
171
|
+
chart.encoding = :extended
|
|
172
|
+
|
|
173
|
+
chart.data "2^i", (0..8).to_a.collect{|i| 2**i}, "ff0000"
|
|
174
|
+
chart.data "2.1^i", (0..8).to_a.collect{|i| 2.1**i}, "00ff00"
|
|
175
|
+
chart.data "2.2^i", (0..8).to_a.collect{|i| 2.2**i}, "0000ff"
|
|
176
|
+
chart.max = (2**8 + 2.1**8 + 2.2**8)
|
|
177
|
+
|
|
178
|
+
chart.axis :left, :range => 0..(chart.max), :color => "000000", :font_size => 16, :alignment => :center
|
|
179
|
+
chart.axis :bottom, :labels => (0..8).to_a, :color => "000000", :font_size => 16, :alignment => :center
|
|
180
|
+
end
|
|
181
|
+
puts "\nBar chart encoding error test"
|
|
182
|
+
puts bc.to_url
|
|
183
|
+
|
|
184
|
+
# Sparklines
|
|
185
|
+
GoogleChart::SparklineChart.new do |sp|
|
|
186
|
+
sp.data "", [3,10,20,37,40,25,68,75,89,99], "ff0000"
|
|
187
|
+
puts "\nSparklines"
|
|
188
|
+
puts sp.to_url
|
|
189
|
+
end
|
|
190
|
+
=end
|
|
191
|
+
|
|
192
|
+
# Maps.
|
|
193
|
+
mc = GoogleChart::MapChart.new do |chart|
|
|
194
|
+
chart.title = "Hospital Procedural Compliance Nationally"
|
|
195
|
+
chart.title_color = '000000'
|
|
196
|
+
chart.title_font_size = 18
|
|
197
|
+
|
|
198
|
+
chart.width = 440
|
|
199
|
+
chart.height = 220
|
|
200
|
+
chart.geographical_area = :usa
|
|
201
|
+
|
|
202
|
+
chart.data :NY, 100
|
|
203
|
+
chart.data :TX, 50
|
|
204
|
+
chart.data :CA, 25
|
|
205
|
+
|
|
206
|
+
chart.default_color = 'FFFFFF'
|
|
207
|
+
chart.gradient = [ 'FF0000', '00FF00', '0000FF' ]
|
|
208
|
+
|
|
209
|
+
chart.fill(:solid, :color => 'EAF7FE')
|
|
210
|
+
|
|
211
|
+
puts "\nMap Chart"
|
|
212
|
+
puts chart.to_url
|
|
213
|
+
end
|
|
214
|
+
|
|
215
|
+
__END__
|
|
216
|
+
# Line Style
|
|
217
|
+
lc = GoogleChart::LineChart.new('320x200', "Line Chart", false) do |lc|
|
|
218
|
+
lc.data "Trend 1", [5,4,3,1,3,5], '0000ff'
|
|
219
|
+
lc.data "Trend 2", [1,2,3,4,5,6], '00ff00'
|
|
220
|
+
lc.data "Trend 3", [6,5,4,3,2,1], 'ff0000'
|
|
221
|
+
lc.line_style 0, :length_segment => 3, :length_blank => 2, :line_thickness => 3
|
|
222
|
+
lc.line_style 1, :length_segment => 1, :length_blank => 2, :line_thickness => 1
|
|
223
|
+
lc.line_style 2, :length_segment => 2, :length_blank => 1, :line_thickness => 5
|
|
224
|
+
end
|
|
225
|
+
puts "\nLine Styles"
|
|
226
|
+
puts lc.to_url
|
|
227
|
+
|
|
228
|
+
puts "\nLine Styles (encoded URL)"
|
|
229
|
+
puts lc.to_escaped_url
|
|
230
|
+
|
|
231
|
+
# Fill Area (Multiple Datasets)
|
|
232
|
+
lc = GoogleChart::LineChart.new('320x200', "Line Chart", false) do |lc|
|
|
233
|
+
lc.show_legend = false
|
|
234
|
+
lc.data "Trend 1", [5,5,6,5,5], 'ff0000'
|
|
235
|
+
lc.data "Trend 2", [3,3,4,3,3], '00ff00'
|
|
236
|
+
lc.data "Trend 3", [1,1,2,1,1], '0000ff'
|
|
237
|
+
lc.data "Trend 4", [0,0,0,0,0], 'ffffff'
|
|
238
|
+
lc.fill_area '0000ff',2,3
|
|
239
|
+
lc.fill_area '00ff00',1,2
|
|
240
|
+
lc.fill_area 'ff0000',0,1
|
|
241
|
+
end
|
|
242
|
+
puts "\nFill Area (Multiple Datasets)"
|
|
243
|
+
puts lc.to_url
|
|
244
|
+
|
|
245
|
+
# Fill Area (Single Datasets)
|
|
246
|
+
lc = GoogleChart::LineChart.new('320x200', "Line Chart", false) do |lc|
|
|
247
|
+
lc.show_legend = false
|
|
248
|
+
lc.data "Trend 1", [5,5,6,5,5], 'ff0000'
|
|
249
|
+
lc.fill_area 'cc6633', 0, 0
|
|
250
|
+
end
|
|
251
|
+
puts "\nFill Area (Single Dataset)"
|
|
252
|
+
puts lc.to_url
|