Class: GoogleChart::ScatterChart

Inherits:
Base
  • Object
show all
Defined in:
lib/google_chart/scatter_chart.rb

Overview

Generates a Scatter chart.

Example

sc = GoogleChart::ScatterChart.new('320x200',"Scatter Chart")
sc.data "Scatter Set", [[1,1,], [2,2], [3,3], [4,4]]
sc.point_sizes [10,15,30,55]
puts sc.to_url

Constant Summary

Constants inherited from Base

Base::BASE_URL, Base::COMPLEX_ENCODING_ALPHABET, Base::DEFAULT_LINE_STYLE, Base::SHAPE_MARKERS, Base::SIMPLE_ENCODING

Instance Attribute Summary

Attributes inherited from Base

#chart_size, #chart_title, #chart_type, #data_encoding, #params, #show_legend, #title_color, #title_font_size

Instance Method Summary collapse

Methods inherited from Base

#axis, #data, #fill, #fill_area, #grid, #max_value, #range_marker, #shape_marker, #to_escaped_url, #to_url

Constructor Details

#initialize(chart_size = '300x200', chart_title = nil) {|_self| ... } ⇒ ScatterChart

Initializes the Scatter Chart with a chart_size (in WIDTHxHEIGHT format) and a chart_title

Yields:

  • (_self)

Yield Parameters:



14
15
16
17
18
19
20
# File 'lib/google_chart/scatter_chart.rb', line 14

def initialize(chart_size='300x200', chart_title=nil) # :yield: self
  super(chart_size, chart_title)
  self.chart_type = :s
  self.show_legend = false
  @point_sizes = []
  yield self if block_given?
end

Instance Method Details

#point_sizes(values) ⇒ Object

Specify the data point sizes of the Scatter chart (optional). The data point sizes are scaled with this data set.



33
34
35
# File 'lib/google_chart/scatter_chart.rb', line 33

def point_sizes(values)            
  @point_sizes = values
end

#process_dataObject



22
23
24
25
26
27
28
29
30
# File 'lib/google_chart/scatter_chart.rb', line 22

def process_data
  # Interleave X and Y co-ordinate data
  encoded_data = join_encoded_data([encode_data(x_data[0],max_x_value), encode_data(y_data[0],max_y_value)])
  # Add point sizes data if it exists
  unless @point_sizes.empty?
    encoded_data = join_encoded_data([encoded_data, encode_data(@point_sizes)])
  end
  return encoded_data
end