| Class | GoogleChart::Base |
| In: |
lib/google_chart/base.rb
|
| Parent: | Object |
| BASE_URL | = | "http://chart.apis.google.com/chart?" |
| SIMPLE_ENCODING | = | 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'.split(''); |
| COMPLEX_ENCODING_ALPHABET | = | 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-.'.split(''); |
| SHAPE_MARKERS | = | {:arrow => "a", :cross => "c", :diamond => "d", :circle => "o", :square => "s", :vline_segment => "v", :vline_full => "V", :hline_full => "h", :x => "x" |
| DEFAULT_LINE_STYLE | = | '1' |
| chart_size | [RW] | Size of the chart in WIDTHxHEIGHT format |
| chart_title | [RW] | Chart title |
| chart_type | [RW] | Type of the chart. Usually, you do not need to set this yourself |
| data_encoding | [RW] | Data encoding to use. Can be one of :simple, :text or :extended (see code.google.com/apis/chart/#chart_data) |
| params | [RW] | A hash of the params used to construct the URL |
| show_legend | [RW] | Set to true or false to show or hide the chart legend. Not applicable for Scatter Chart. |
| title_color | [RW] | RRGGBB hex value for the color of the title |
| title_font_size | [RW] | Font size of the title |
Adds an axis to the graph. Not applicable for Pie Chart (GoogleChart::PieChart) or Venn Diagram (GoogleChart::VennDiagram)
Not all the options are mandatory.
axis styling options have to be specified as follows
lc.axis :y, :range => [0,6], :color => 'ff00ff', :font_size => 16, :alignment => :center
Adds the data to the chart, according to the type of the graph being generated.
for GoogleChart::LineChart (normal)
lc.data "Trend 1", [1,2,3,4,5], 'ff00ff'
for GoogleChart::LineChart (XY chart)
lc.data "Trend 2", [[4,5], [2,2], [1,1], [3,4]], 'ff00ff'
lc.data "Apples", 5, 'ff00ff' lc.data "Oranges", 7, '00ffff'
Adds a background or chart fill. Call this option twice if you want both a background and a chart fill
For :solid type
For :gradient type
For :stripes type
Defines a Fill area. Applicable for line charts only
# Fill Area (Multiple Datasets)
lc = GoogleChart::LineChart.new('320x200', "Line Chart", false) do |lc|
lc.show_legend = false
lc.data "Trend 1", [5,5,6,5,5], 'ff0000'
lc.data "Trend 2", [3,3,4,3,3], '00ff00'
lc.data "Trend 3", [1,1,2,1,1], '0000ff'
lc.data "Trend 4", [0,0,0,0,0], 'ffffff'
lc.fill_area '0000ff',2,3
lc.fill_area '00ff00',1,2
lc.fill_area 'ff0000',0,1
end
puts "\nFill Area (Multiple Datasets)"
puts lc.to_url
# Fill Area (Single Dataset)
lc = GoogleChart::LineChart.new('320x200', "Line Chart", false) do |lc|
lc.show_legend = false
lc.data "Trend 1", [5,5,6,5,5], 'ff0000'
lc.fill_area 'cc6633', 0, 0
end
puts "\nFill Area (Single Dataset)"
puts lc.to_url
Adds a grid to the graph. Applicable only for Line Chart (GoogleChart::LineChart) and Scatter Chart (GoogleChart::ScatterChart)
lc.grid :x_step => 5, :y_step => 5, :length_segment => 1, :length_blank => 0
Allows (optional) setting of a max value for the chart, which will be used for data encoding and axis plotting. The value to pass depends on the type of chart
For bar charts
bc.max_value 5 # 5 will be used to calculate the relative encoding values
For scatter chart
sc.max_value [5,6] # 5 is the max x value and 6 is the max y value
Note : MAKE SURE you are passing the right values otherwise an exception will be raised
Defines a horizontal or vertical range marker. Applicable for line charts and vertical charts
lc.range_marker :horizontal, :color => 'E5ECF9', :start_point => 0.1, :end_point => 0.5
lc.range_marker :vertical, :color => 'a0bae9', :start_point => 0.1, :end_point => 0.5
Defines a shape marker. Applicable for line charts and scatter plots
lcxy.shape_marker :circle, :color => "000000", :data_set_index => 1, :data_point_index => 2, :pixel_size => 10
lcxy.shape_marker :cross, :color => "E5ECF9", :data_set_index => 0, :data_point_index => 0.5, :pixel_size => 10
Generates a fully encoded URL string that can be used to retrieve the graph image in PNG format. For less verbose URLs, use the to_url method. Use this only if you are doing further processing with the URLs, like passing the URL to a method for downloading the images
Use this after assigning all the properties to the graph You can pass in additional params as a hash for features that may not have been implemented For e.g
lc = GoogleChart::LineChart.new('320x200', "Line Chart", false)
lc.data "Trend 1", [5,4,3,1,3,5,6], '0000ff'
lc.data "Trend 2", [1,2,3,4,5,6], '00ff00'
lc.data "Trend 3", [6,5,4,3,2,1], 'ff0000'
puts lc.to_escaped_url({:chm => "000000,0,0.1,0.11"}) # Single black line as a horizontal marker
Generates the URL string that can be used to retrieve the graph image in PNG format. Use this after assigning all the properties to the graph You can pass in additional params as a hash for features that may not have been implemented For e.g
lc = GoogleChart::LineChart.new('320x200', "Line Chart", false)
lc.data "Trend 1", [5,4,3,1,3,5,6], '0000ff'
lc.data "Trend 2", [1,2,3,4,5,6], '00ff00'
lc.data "Trend 3", [6,5,4,3,2,1], 'ff0000'
puts lc.to_url({:chm => "000000,0,0.1,0.11"}) # Single black line as a horizontal marker