gchartrb 0.6 released, with new features On Sunday, January 27, 2008

I spent a bit of time hacking on a lazy Sunday afternoon and managed to get out version 0.6 of gchartrb. This blog post is to illustrate the three new features that I managed to put in.

I added support for the undocumented lfi chart type, which is mentioned here, due to a request that came in. Please note that the support is experimental, until Google documents it. Here is a sample usage

# Financial Line Chart (Experimental)
flc = GoogleChart::FinancialLineChart.new do |chart|
  chart.data "", [3,10,20,37,40,25,68,75,89,99], "ff0000"
end
puts "\nFinancial Line Chart or Sparklines (EXPERIMENTAL)"
puts flc.to_url

The output is

Sparklines

Second, I added the Line Styles feature. Here is the sample usage

# Line Style
lc = GoogleChart::LineChart.new('320x200', "Line Chart", false) do |lc|
  lc.data "Trend 1", [5,4,3,1,3,5], '0000ff'
  lc.data "Trend 2", [1,2,3,4,5,6], '00ff00'
  lc.data "Trend 3", [6,5,4,3,2,1], 'ff0000'
  lc.line_style 0, :length_segment => 3, :length_blank => 2, :line_thickness => 3
  lc.line_style 1, :length_segment => 1, :length_blank => 2, :line_thickness => 1
  lc.line_style 2, :length_segment => 2, :length_blank => 1, :line_thickness => 5
end
puts "\nLine Styles"
puts lc.to_url

which leads to

Line Styles

Last, I finally added support for customisable widths and spacing in bar charts.

# Bar Chart
GoogleChart::BarChart.new('800x200', "Bar Chart", :vertical, false) do |bc|
  bc.data "Trend 1", [5,4,3,1,3,5], '0000ff' 
  bc.data "Trend 2", [1,2,3,4,5,6], 'ff0000'
  bc.data "Trend 3", [6,5,4,4,5,6], '00ff00'
  bc.width_spacing_options :bar_width => 5, :bar_spacing => 2, :group_spacing => 10
  puts "\nBar Chart"
  puts bc.to_url
end

which results in

Bar Chart

chap March 26, 2008 7:40 AM  

Can you post a simple example of how to get the graph to render in the view?

Deepak March 26, 2008 7:52 AM  

@Chap : Could you please elaborate on your question. I do not quite follow what you need.

chap March 26, 2008 7:56 AM  

Unfortunately I'm getting errors when I try to join the google discussion group and blogger won't let me paste "<" into the comments, but I'm just trying to figure out the cleanest way to get a graph into my view.

I'll replace "<" with "{" so that blogger will allow it.

controller.rb
def index
line_chart_xy = GoogleChart::LineChart.new('320x200', "Line XY Chart", true) do |lcxy|
lcxy.data "Trend 1", [[1,1], [2,2], [3,3], [4,4]], '0000ff'
@graph= lcxy.to_url
end
end

index.html.erb
{img src="{%= @graph %}"/}

chap March 26, 2008 8:10 AM  

My google groups membership went through, so I posted this there.