Generates a Line chart. An option can be passed that allows you to create a Line XY Chart
# Line Chart 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' lc.axis :y, :range => [0,6], :color => 'ff00ff', :font_size => 16, :alignment => :center lc.axis :x, :range => [0,6], :color => '00ffff', :font_size => 16, :alignment => :center # Line XY Chart lcxy = GoogleChart::LineChart.new('320x200', "Line XY Chart", true) lcxy.data "Trend 1", [[1,1], [2,2], [3,3], [4,4]], '0000ff' lcxy.data "Trend 2", [[4,5], [2,2], [1,1], [3,4]], '00ff00' puts lcxy.to_url
Specify the
chart_size
in WIDTHxHEIGHT format
chart_title
as a string
is_xy
is false
by default. Set it to
true
if you want to plot a Line XY chart
# File lib/google_chart/line_chart.rb, line 28 def initialize(chart_size='300x200', chart_title=nil, is_xy=false) # :yield: self super(chart_size, chart_title) self.is_xy = is_xy @line_styles = [] yield self if block_given? end
Pass in true
here to create a Line XY.
Note: This must be done before passing in any data to the chart
# File lib/google_chart/line_chart.rb, line 38 def is_xy=(value) @is_xy = value if value self.chart_type = :lxy else self.chart_type = :lc end end
Defines a line style. Applicable for line charts.
data_set_index
Can be one of :background
or :chart
depending on
the kind of fill requested
options
: Options for the style, specifying things like line thickness and lengths of the line segment and blank portions
:line_thickness
(mandatory) option which specifies the
thickness of the line segment in pixels
:length_segment
, which specifies the length of the line
segment
:length_blank
, which specifies the lenght of the blank segment
# File lib/google_chart/line_chart.rb, line 55 def line_style(data_set_index, options={}) @line_styles[data_set_index] = "#{options[:line_thickness]}" @line_styles[data_set_index] += ",#{options[:length_segment]},#{options[:length_blank]}" if options[:length_segment] end
# File lib/google_chart/line_chart.rb, line 60 def process_data if self.is_xy or @data.size > 1 if self.is_xy # XY Line graph data series encoded_data = [] @data.size.times { |i| # Interleave X and Y co-ordinate data encoded_data << join_encoded_data([encode_data(x_data[i],max_x_value), encode_data(y_data[i],max_y_value)]) } join_encoded_data(encoded_data) else # Line graph multiple data series join_encoded_data(@data.collect { |series| encode_data(series, max_data_value) }) end else encode_data(@data.flatten, max_data_value) end end