jessepinho / dashing-graph

A graph class for use with Shopify's Dashing and the Rickshaw JavaScript library
6 stars 1 forks source link

Dashing-Graph

A class for preparing Rickshaw graphs for Dashing.

The following example uses the Graph class along with the Sequel gem to count the number of users and orders per day, then plot them as separate series on the graph.

graph = DashingGraph.new 'Users' => '#ff0000',
                         'Orders' => '#00ff00'
db[:users]
  .select(:created_at)
  .each do |row|
    # Group by day
    time = Time.at(row[:created_at]).to_datetime.at_beginning_of_day.to_i,
    # Add to the graph
    graph.add_point 'Users', time, 1
  end

db[:orders]
  .select(:created_at)
  .each do |row|
    # Group by day
    time = Time.at(row[:created_at]).to_datetime.at_beginning_of_day.to_i,
    # Add to the graph
    graph.add_point 'Orders', time, 1
  end

send_event('users-and-orders-per-day', graph)

To do

Thanks to Tim Macdonald for writing all the original graph-data-massaging code that made this class possible.