google_otg

Author

Eric Silverberg (www.ericsilverberg.com)

Copyright

Copyright © 2009 Eric Silverberg

License

MIT (Go Beavers!)

Git

github.com/esilverberg/google_otg/tree/master

This plugin adds helpers to include Google’s pretty over time line graph in your rails application. You will recognize this line graph from Google Analytics.

Many features are missing, including support for multiple lines and colors. Feel free to add.

Requirements

You must be able to generate arrays of objects that respond to “count” and “created_at”. The X-axis is presumed to be dates. You can control time step of the x-axis.

Example Usage

In your controller:

@hits_last_week = Hits.find_by_sql(["
   SELECT 
       DAYOFYEAR(hits.created_at) as d, 
       DATE(hits.created_at) as created_at, 
       count(*) as count
   FROM hits
   WHERE hits.created_at > UTC_TIMESTAMP() - INTERVAL 7 DAY
   GROUP BY d
   ORDER BY created_at"])

In your view:

<%= over_time_graph(@hits_last_week) %>
or
<%= over_time_graph(@hits_last_week, :label => "Hits", :range => 1440, :x_label_format => "%A, %B %d", :src => "/google/OverTimeGraph.swf") %>

over_time_graph

Some of the options available:

:label

The label of quantity being measured

:range

The time step, in minutes

:x_label_format

The time format for the x label

:src

An optional local source to serve this widget (otherwise will serve from Google)

google_line_graph

Example:

Some of the options available:

google_line_graph(
    [@impressions, @conversions],
    :x_label_format => "%a, %b %d", 
    :time_zone => @time_zone, 
    :range => 1440,
    :title => @company_name,
    :legend => ['Impressions','Conversions'])
:title

The title of this graph

:legend

The graph legend

:title_color

The title color

:title_size

Title font size

:grid_lines

Grid lines on the graph

Copyright © 2009 esilverberg. See LICENSE for details.