Permalink
Browse files

Some experiments with Highcharts.

  • Loading branch information...
1 parent b5bf470 commit f90c70005f4a917522cb58e6787f1d353d14dbcc @jcxplorer committed Mar 3, 2011
Showing with 227 additions and 1 deletion.
  1. +2 −1 config/application.rb
  2. +63 −0 public/javascripts/application.js
  3. +162 −0 public/javascripts/highcharts.js
@@ -31,7 +31,8 @@ class Application < Rails::Application
# config.i18n.default_locale = :de
# JavaScript files you want as :defaults (application.js is always included).
- config.action_view.javascript_expansions[:defaults] = %w(jquery rails)
+ config.action_view.javascript_expansions[:defaults] =
+ %w(jquery rails highcharts)
# Configure the default encoding used in templates for Ruby 1.9.
config.encoding = "utf-8"
@@ -1,2 +1,65 @@
jQuery(function() {
+
+ if ($("#pulse[data-source]").length) {
+ var path = $("#pulse").attr("data-source");
+ var last_pageviews;
+
+ $.getJSON(path, function(data) {
+ var chart = new Highcharts.Chart({
+ chart: { renderTo: "pulse", type: "spline" },
+ title: { text: "Pulse" },
+ legend: { enabled: false },
+ plotOptions: { spline: { lineWidth: 1, shadow: false } },
+ xAxis: { type: "datetime" },
+ yAxis: { title: null, allowDecimals: false, startOnTick: false, minPadding: 0.1 },
+ series: [{ data: [] }],
+ credits: { enabled: false }
+ });
+
+ setInterval(function() {
+ $.getJSON(path, function(data) {
+ var move = chart.series[0].data.length > 9,
+ pageviews = data.pageviews[data.pageviews.length-1],
+ time = Math.floor((new Date).getTime()/1000) * 1000,
+ diff = 0;
+
+ if (pageviews > last_pageviews) { diff = pageviews - last_pageviews; }
+ if (pageviews < last_pageviews) { diff = pageviews; }
+
+ chart.series[0].addPoint([time, diff], true, move);
+ last_pageviews = pageviews;
+ });
+ }, 1000);
+ });
+ }
+
+ function addPulse(chart) {
+ var time = new Date().getTime();
+ chart.series[0].addPoint([time, Math.random()]);
+ }
+
+ if ($("#pageviews[data-source]").length) {
+ $.getJSON($("#pageviews").attr("data-source"), function(data) {
+ var chart = new Highcharts.Chart({
+ chart: { renderTo: "pageviews", defaultSeriesType: "spline" },
+ plotOptions: { series: { animation: false }, spline: { lineWidth: 3 } },
+ title: { text: "Pageviews and Visits" },
+ xAxis: { categories: data.hours, tickInterval: 2, tickWidth: 0 },
+ yAxis: { title: null, min: 0 },
+ legend: { enabled: false },
+ tooltip: { shared: true, crosshairs: true },
+ series: [
+ { name: "Pageviews", data: data.pageviews },
+ { name: "Visits", data: data.visits }
+ ],
+ credits: { enabled: false }
+ });
+
+ setTimeout(function() {
+ chart.series[0].setData([1,2,3,4,5,6,10,6,4,4,2,4]);
+ chart.series[1].setData([2,3,4,5,6,7,6,4,3,2,4,3]);
+ }, 5000);
+ });
+ }
+
});
Oops, something went wrong.

0 comments on commit f90c700

Please sign in to comment.