Skip to content
Permalink
Browse files

RealTime analytics working, with random JS data

  • Loading branch information
penso committed May 23, 2013
1 parent 33fadea commit 82f245c7f8dc353eb3336372230b88fb8cc84fc3
@@ -0,0 +1,3 @@
# Place all the behaviors and hooks related to the matching controller here.
# All this logic will automatically be available in application.js.
# You can use CoffeeScript in this file: http://jashkenas.github.com/coffee-script/
@@ -16,3 +16,69 @@
//
//= require highcharts
//= require highcharts/highcharts-more

$(function() {
// Create the chart
$('#container').highcharts({
chart: {
type: 'area',
plotBorderWidth: 0,
events: {
load: function() {
// set up the updating of the chart each second
var series = this.series[0];
setInterval(function() {
var x = (new Date()).getTime(), // current time

// Previous value +/- 10 max
y = Math.round(series.data.slice(-1)[0]['y'] + (Math.random() * 10 * (Math.round(Math.random()) * 2 - 1)));
if (y < 0) {
y = -y
}
series.addPoint([x, y], true, true);
}, 1000);
}
}
},
title: {
text: 'Live random data'
},
xAxis: {
type: 'datetime'
},
yAxis: {
gridLineWidth: 0.3,
title: {text: ""}
},
plotOptions: {
area: {
fillOpacity: 0.35,
states: {
hover: {
enabled: false
}
},
marker: {
enabled: true,
symbol: 'circle',
radius: 2
}
}
},
legend: { enabled: false },
credits: { enabled: false },
series: [{
name: 'Random data',
lineWidth: 2,
data: (function() {
// generate an array of random data
var data = [], time = (new Date()).getTime(), i;
var previous;
for( i = -60; i <= 0; i+=1) {
data.push([time + i * 1000, Math.round(Math.random() * 100)]);
}
return data;
})()
}]
});
});
@@ -0,0 +1,9 @@
// Place all the styles related to the analytics controller here.
// They will automatically be included in application.css.
// You can use Sass (SCSS) here: http://sass-lang.com/
#container {
width: 500px;
margin: auto;
height: 300px;
min-width: 300px;
}
@@ -0,0 +1,5 @@
class AnalyticsController < ApplicationController
def index

end
end
@@ -0,0 +1,2 @@
module AnalyticsHelper
end
@@ -0,0 +1,3 @@

<div id="container"></div>

@@ -1,58 +1,3 @@
BlogSse::Application.routes.draw do
# The priority is based upon order of creation:
# first created -> highest priority.

# Sample of regular route:
# match 'products/:id' => 'catalog#view'
# Keep in mind you can assign values other than :controller and :action

# Sample of named route:
# match 'products/:id/purchase' => 'catalog#purchase', :as => :purchase
# This route can be invoked with purchase_url(:id => product.id)

# Sample resource route (maps HTTP verbs to controller actions automatically):
# resources :products

# Sample resource route with options:
# resources :products do
# member do
# get 'short'
# post 'toggle'
# end
#
# collection do
# get 'sold'
# end
# end

# Sample resource route with sub-resources:
# resources :products do
# resources :comments, :sales
# resource :seller
# end

# Sample resource route with more complex sub-resources
# resources :products do
# resources :comments
# resources :sales do
# get 'recent', :on => :collection
# end
# end

# Sample resource route within a namespace:
# namespace :admin do
# # Directs /admin/products/* to Admin::ProductsController
# # (app/controllers/admin/products_controller.rb)
# resources :products
# end

# You can have the root of your site routed with "root"
# just remember to delete public/index.html.
# root :to => 'welcome#index'

# See how all your routes lay out with "rake routes"

# This is a legacy wild controller route that's not recommended for RESTful applications.
# Note: This route will make all actions in every controller accessible via GET requests.
# match ':controller(/:action(/:id))(.:format)'
root to: 'analytics#index'
end

0 comments on commit 82f245c

Please sign in to comment.
You can’t perform that action at this time.