Git Product home page Git Product logo

google_otg's Introduction

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.

You can also download images via integration with the Google chart API as well as download CSV

See a live example at www.picostatus.com/reports/1J6v2eQ

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(TIMESTAMPADD(SECOND, ?, created_at)) as d, 
           DATE(TIMESTAMPADD(SECOND, ?, created_at)) as created_at, 
           count(*) as count
       FROM hits
       WHERE widget_id = ?

       AND created_at >= TIMESTAMPADD(SECOND, -1 * ?, DATE(?))
       AND created_at <= TIMESTAMPADD(SECOND, -1 * ?, DATE(?)) + INTERVAL 1 DAY

       GROUP BY d
       ORDER BY created_at  
   ", utc_offset_in_sec, utc_offset_in_sec, widget.id, utc_offset_in_sec, lower_bound, utc_offset_in_sec, upper_bound])

In your view:

<%= over_time_graph(@hits_last_week) %>

or

<%= over_time_graph(@hits_last_week, 
      :x_label_format => "%A, %B %d", 
      :max_x_label_count => 3,
      :time_zone => @time_zone,
      :range => @range,
      :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:

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

Some of the options available:

: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

data_to_csv

Example:

data_to_csv([@impressions, @conversions], 
        :legend => ['Impressions','Conversions'],
        :x_label_format => "%m/%d/%Y", 
        :time_zone => ActiveSupport::TimeZone['Hawaii'],
        :range => {:lower_bound => 1.day.ago, 
                   :upper_bound => 1.day.fromnow})

Some of the options available:

:legend

Column headers

:time_zone

Time zone of data

:range

Lower & upper bound

:x_label_format

Format string for x-axis data

Copyright © 2009 esilverberg. See LICENSE for details.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.