SlideShare a Scribd company logo
JQuery Flot
 by Arshavski Alexander
Charting libraries



A lot of choices -
http://my.opera.com/tagawa/blog/list-of-javascript-ch
Good list of
       features


http://socialcompare.com/en/comparison/javascript-g
Should work
  offline
Date-time axis
...
Flot works on:
Firefox 2.x+

Safari 3.0+

Opera 9.5+

Konqueror 4.x+

Internet Explorer 6+ (the excanvas
Javascript emulation helper is used for
IE < 9)
A lot of plugins
  and examples
Plugins -
http://code.google.com/p/flot/wiki/Plugins

Bubble charts -
https://github.com/ubermajestix/flot-plugins

Usage examples:
http://code.google.com/p/flot/wiki/FlotUsage
It’s not all pink and
         rosy

  Documentation sucks!
That’s why I’m here
What I want to do?
What I want to do?
What I want to do?
Imports
<link type="text/css" href="...jquery-ui.css">
<link type="text/css" href="...flot_layout.css" >
<link type="text/css" href="...jquery-ui-1.8.16.custom.css">

<script type="text/javascript" src="...jquery-1.5.1.min.js"></script>
<script type="text/javascript" src="...jquery-ui-1.8.10.custom.min.js"></script>
<script type="text/javascript" src="...jquery.flot.min.js"></script>
<script type="text/javascript" src="...jquery.flot.pie.min.js"></script>
<script type="text/javascript" src="...jquery.blockUI.js"></script>
Radio buttons

  <div id="radio">
     <input type="radio" id="connections_radio" name="radio"
checked="checked" /><label for="connections_radio">Connections</label>
     <input type="radio" id="usage_radio" name="radio" /><label
for="usage_radio">Usage</label>
     <input type="radio" id="export_radio" name="radio" /><label
for="export_radio">Export</label>
  </div>
Tabs
<div id="usage" style="display: none">
  <div id="usage_tabs">
      <ul>
          <li><a href="#day_statistics">Day</a></li>
          <li><a href="#week_statistics">Week</a></li>
          <li><a href="#month_statistics">Month</a></li>
          <li><a href="#year_statistics">Year</a></li>
      </ul>
      <div id="day_statistics">
          <div id="graphs_container1" class="graph_container”>
             <div id="graph1"></div>
             <div id="graph1_legend" class="graph_legend"></div>
          </div>
      </div>
      ...
      </div>
  ...
</div>
Radio buttons
$(function () {
   $("#connections_radio").click(function(event) {
      $("#connections").show();
      $("#usage").hide();
       $("#export").hide();
   });
   $("#usage_radio").click(function(event) {
      $("#connections").hide();
       $("#usage").show();
       $("#export").hide();
   });
   $("#export_radio").click(function(event) {
       $("#connections").hide();
       $("#usage").hide();
       $("#export").show();
   });
});
Tabs


$(function () {
   ...
   $("#connections_tabs").tabs();
   $("#usage_tabs").tabs();
   $("#usage_distribution_tabs").tabs();
});
Till now...
As a
  python
 guy it’s a
  lot of
 code for
    me
 already,
  so it’s
gonna be a
   mess
Refactoring
<script type="text/javascript" src="...statistics.js"></script>

$(function () {
   ...
   get_connections_statistics();
   get_usage_statistics();
   get_api_distribution_statistics();
   get_distribution_statistics();
   ...
});

{% include "statistics/connections.html" %}
{% include "statistics/usage.html" %}
{% include "statistics/export.html" %}
And now to the main
           part...
  var weekdayNames = "Sunday Monday Tuesday Wednesday Thursday Friday
Saturday".split(" ");
  var shortMonthNames = "Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov
Dec".split(" ");

  $.get('/manage/get_statistics_usage_data', {}, function(data){
    var stat_data = jQuery.parseJSON(data);

    //variables init
    var now = new Date().getTime() + stat_data.time_offset;
    var weekday = new Date(now).getDay();
    var month = new Date(now).getMonth();
    ...
And now to the main
         part...
//building weekly data
var api_calls_points = stat_data.api_calls_weekly;
var bandwidth_points = stat_data.bandwidth_weekly;
for(var i=0; i<api_calls_points.length; i++) {
    graph2_ticks.push([7-i, weekdayNames[(weekday+7-i)%7]]);
    api_calls_weekly.push([i, api_calls_points[i]]);
    bandwidth_weekly.push([i, bandwidth_points[i]]);
}
...
//building yearly data
var api_calls_points = stat_data.api_calls_yearly;
var bandwidth_points = stat_data.bandwidth_yearly;
for(var i=0; i<api_calls_points.length; i++) {
    graph4_ticks.push([12-i, shortMonthNames[(month+12-i)%12]]);
    api_calls_yearly.push([i, api_calls_points[i]]);
    bandwidth_yearly.push([i, bandwidth_points[i]]);
}
And now to the main
         part...
var options2 = {
   legend: {
      position: "ne",
      container: $("#graph2_legend")
   }, xaxis: {
      ticks: graph2_ticks
   }, yaxis: {
      min: 0,
      tickDecimals: 0 //only whole numbers
   }, grid: { hoverable: true }
};

    xaxis: { //in case of time axis
       mode: "time",
       timeformat: "%H:%M"
    },
And now to the main
         part...
var usage_plot2 = $.plot($("#graph2"), [
   {
      data: api_calls_weekly,
      label: "API calls",
      lines: { show: true }
   },
   {
      label: "Bandwidth (KB)",
      data: bandwidth_weekly,
      lines: { show: true }
   },
], options2);
Till now...
What if I want to
select a graph?
Graph Select
$('.legendColorBox').parent().click(function() {
  var plot = usage_plot1;
  var data = [api_calls_daily, bandwidth_daily];
  var graph = $(this).parent().parent().parent().attr("id").split("_")[0];
  if (graph == "graph2") {
      plot = usage_plot2;
      data = [api_calls_weekly, bandwidth_weekly];
  }
  ...
  if ($(this).children().text() == "API calls”) {
      plot.setData(get_plot_data([data[0], null, "lines", [], null, "lines"]));
  }
  if ($(this).children().text() == "Bandwidth (KB)") {
      plot.setData(get_plot_data([[], null, "lines", data[1], null, "lines"]));
  }
  plot.draw();
  ...
Graph Select
     var ticks = [graph2_ticks, graph3_ticks, graph4_ticks];
     if ($(this).siblings().text().search("Show all") == -1) {
        $('<tr/>', {
           style: 'cursor: auto;'
        }).bind('click', {plot: plot, data: data, ticks: ticks, now: now},
           show_all_usage_graphs)
        .append("<td class='legendColorBox'></td><td>Show all</td>").appendTo($
(this).parent());
        }
     });

function show_all_usage_graphs(e) {
    e.data.plot.setData(get_plot_data([e.data.data[0], null, "lines",
       e.data.data[1], null, "lines"]));
    e.data.plot.draw();
    $(this).remove();
  }
Till now...
What about
        tooltips?


I could take them from a lot of places. For
example: http://jquerytools.org/
I decided to do it
      myself
Tooltips
function add_usage_tooltips(now, ticks) {
  for (var i=1; i<=4; i++) {
     ...
     $("#graph" + i).bind("plothover", function (event, pos, item) {
         draw_tooltip(item, tick, now);
     });
  }
}

function draw_tooltip(item, ticks, now) {
  ...
  var tooltip = get_tooltip_message(item, ticks, now);
  showChartTooltip(tooltip, item);
  ...
}
Tooltips
function showChartTooltip(contents, item) {
  ...
  $("<div id='charttooltip'>" + contents + "</div>").css(
      {
         position: 'absolute',
         display: 'none',
         top: item.pageY + 5,
         left: item.pageX + 5,
         border: '1px solid #bfbfbf',
         padding: '2px',
         'background-color': item.series.color,
         opacity: 1
      }).appendTo("body").fadeIn(200);
  ...
}
Till now...
How can I make
                  bars?

$.plot($("#graph2"), [
   {
       data: api_calls_weekly,
       label: "Clients API hourly",
       bars: { show: true } //instead of: lines: { show: true }
   },
   ...
], options2);
By the way tooltips
   on bars looks
      good...
For charts you
              should add:


<script type="text/javascript" src="...jquery.flot.pie.min.js"></script>
Charts
   var options = {
      series: {
        pie: {
           show: true,
           radius: 1,
           label: {
               show: true,
               radius: 3/4,
               formatter: function(label, series){
                 return '<div style="font-size:12pt;text-
align:center;padding:2px;color:black;">'+label+'<br/>'+Math.round(series.percent)+'%</
div>';              },                     background: { opacity: 0.5 }
           }
         }
      }
   };
   $.plot($("#countries_piechart"), data, options);
One last thing...



JQuery BlockUI Plugin:
http://jquery.malsup.com/block/
BlockUI
<script type="text/javascript" src="...jquery.blockUI.js"></script>

$(function () {
  ...
  var message = '<img src=".../loader.gif" /> Please wait...';
  $("#usage_tabs").block({ message: message });
  ...
  get_usage_statistics();
  ...
}

function get_usage_statistics() {
  $.get('.../get_statistics_usage_data', {}, function(data){
     ...
     $("#usage_tabs").unblock();
  });
}
BlockUI
Questions?


     alexarsh5@gmail.com

     http://twitter.com/alexarsh

     http://www.linkedin.com/pub

More Related Content

What's hot

Using a mobile phone as a therapist - Superweek 2018
Using a mobile phone as a therapist - Superweek 2018Using a mobile phone as a therapist - Superweek 2018
Using a mobile phone as a therapist - Superweek 2018
Peter Meyer
 
PhoneGap: Local Storage
PhoneGap: Local StoragePhoneGap: Local Storage
PhoneGap: Local Storage
Ivano Malavolta
 
Crowdsourcing with Django
Crowdsourcing with DjangoCrowdsourcing with Django
Crowdsourcing with Django
Simon Willison
 
Supstat nyc subway
Supstat nyc subwaySupstat nyc subway
Supstat nyc subway
Vivian S. Zhang
 
画像Hacks
画像Hacks画像Hacks
画像Hacks
Yusuke Wada
 
An Elephant of a Different Colour: Hack
An Elephant of a Different Colour: HackAn Elephant of a Different Colour: Hack
An Elephant of a Different Colour: Hack
Vic Metcalfe
 
Advanced jQuery
Advanced jQueryAdvanced jQuery
Advanced jQuery
sergioafp
 
HTML5 and CSS3 Refresher
HTML5 and CSS3 RefresherHTML5 and CSS3 Refresher
HTML5 and CSS3 Refresher
Ivano Malavolta
 
ELK Stack - Turn boring logfiles into sexy dashboard
ELK Stack - Turn boring logfiles into sexy dashboardELK Stack - Turn boring logfiles into sexy dashboard
ELK Stack - Turn boring logfiles into sexy dashboard
Georg Sorst
 
Javascript & jQuery: A pragmatic introduction
Javascript & jQuery: A pragmatic introductionJavascript & jQuery: A pragmatic introduction
Javascript & jQuery: A pragmatic introduction
Iban Martinez
 
Drupal Mobile
Drupal MobileDrupal Mobile
Drupal Mobile
Ruben Teijeiro
 
droidQuery: The Android port of jQuery
droidQuery: The Android port of jQuerydroidQuery: The Android port of jQuery
droidQuery: The Android port of jQuery
PhDBrown
 
MongoDB Aggregation Framework in action !
MongoDB Aggregation Framework in action !MongoDB Aggregation Framework in action !
MongoDB Aggregation Framework in action !
Sébastien Prunier
 
Node.js - Demnächst auf einem Server in Ihrer Nähe
Node.js - Demnächst auf einem Server in Ihrer NäheNode.js - Demnächst auf einem Server in Ihrer Nähe
Node.js - Demnächst auf einem Server in Ihrer Nähe
Ralph Winzinger
 
Daily notes
Daily notesDaily notes
Daily notes
meghendra168
 
jQuery Data Manipulate API - A source code dissecting journey
jQuery Data Manipulate API - A source code dissecting journeyjQuery Data Manipulate API - A source code dissecting journey
jQuery Data Manipulate API - A source code dissecting journey
Huiyi Yan
 
20160227 Granma
20160227 Granma20160227 Granma
20160227 Granma
Sharon Liu
 
A Short Introduction To jQuery
A Short Introduction To jQueryA Short Introduction To jQuery
A Short Introduction To jQuery
Sudar Muthu
 
SVCC 2013 D3.js Presentation (10/05/2013)
SVCC 2013 D3.js Presentation (10/05/2013)SVCC 2013 D3.js Presentation (10/05/2013)
SVCC 2013 D3.js Presentation (10/05/2013)
Oswald Campesato
 

What's hot (20)

Using a mobile phone as a therapist - Superweek 2018
Using a mobile phone as a therapist - Superweek 2018Using a mobile phone as a therapist - Superweek 2018
Using a mobile phone as a therapist - Superweek 2018
 
PhoneGap: Local Storage
PhoneGap: Local StoragePhoneGap: Local Storage
PhoneGap: Local Storage
 
Crowdsourcing with Django
Crowdsourcing with DjangoCrowdsourcing with Django
Crowdsourcing with Django
 
Supstat nyc subway
Supstat nyc subwaySupstat nyc subway
Supstat nyc subway
 
画像Hacks
画像Hacks画像Hacks
画像Hacks
 
An Elephant of a Different Colour: Hack
An Elephant of a Different Colour: HackAn Elephant of a Different Colour: Hack
An Elephant of a Different Colour: Hack
 
Advanced jQuery
Advanced jQueryAdvanced jQuery
Advanced jQuery
 
HTML5 and CSS3 Refresher
HTML5 and CSS3 RefresherHTML5 and CSS3 Refresher
HTML5 and CSS3 Refresher
 
ELK Stack - Turn boring logfiles into sexy dashboard
ELK Stack - Turn boring logfiles into sexy dashboardELK Stack - Turn boring logfiles into sexy dashboard
ELK Stack - Turn boring logfiles into sexy dashboard
 
Javascript & jQuery: A pragmatic introduction
Javascript & jQuery: A pragmatic introductionJavascript & jQuery: A pragmatic introduction
Javascript & jQuery: A pragmatic introduction
 
Drupal Mobile
Drupal MobileDrupal Mobile
Drupal Mobile
 
droidQuery: The Android port of jQuery
droidQuery: The Android port of jQuerydroidQuery: The Android port of jQuery
droidQuery: The Android port of jQuery
 
MongoDB Aggregation Framework in action !
MongoDB Aggregation Framework in action !MongoDB Aggregation Framework in action !
MongoDB Aggregation Framework in action !
 
Node.js - Demnächst auf einem Server in Ihrer Nähe
Node.js - Demnächst auf einem Server in Ihrer NäheNode.js - Demnächst auf einem Server in Ihrer Nähe
Node.js - Demnächst auf einem Server in Ihrer Nähe
 
Daily notes
Daily notesDaily notes
Daily notes
 
jQuery Data Manipulate API - A source code dissecting journey
jQuery Data Manipulate API - A source code dissecting journeyjQuery Data Manipulate API - A source code dissecting journey
jQuery Data Manipulate API - A source code dissecting journey
 
20160227 Granma
20160227 Granma20160227 Granma
20160227 Granma
 
Php
PhpPhp
Php
 
A Short Introduction To jQuery
A Short Introduction To jQueryA Short Introduction To jQuery
A Short Introduction To jQuery
 
SVCC 2013 D3.js Presentation (10/05/2013)
SVCC 2013 D3.js Presentation (10/05/2013)SVCC 2013 D3.js Presentation (10/05/2013)
SVCC 2013 D3.js Presentation (10/05/2013)
 

Similar to JQuery Flot

Big Data for each one of us
Big Data for each one of usBig Data for each one of us
Big Data for each one of usOSCON Byrum
 
Modular and Event-Driven JavaScript
Modular and Event-Driven JavaScriptModular and Event-Driven JavaScript
Modular and Event-Driven JavaScript
Eduardo Shiota Yasuda
 
jQuery: Tips, tricks and hints for better development and Performance
jQuery: Tips, tricks and hints for better development and PerformancejQuery: Tips, tricks and hints for better development and Performance
jQuery: Tips, tricks and hints for better development and Performance
Jonas De Smet
 
Aplicacoes dinamicas Rails com Backbone
Aplicacoes dinamicas Rails com BackboneAplicacoes dinamicas Rails com Backbone
Aplicacoes dinamicas Rails com Backbone
Rafael Felix da Silva
 
Data visualization in python/Django
Data visualization in python/DjangoData visualization in python/Django
Data visualization in python/Django
kenluck2001
 
Jarv.us Showcase — SenchaCon 2011
Jarv.us Showcase — SenchaCon 2011Jarv.us Showcase — SenchaCon 2011
Jarv.us Showcase — SenchaCon 2011Chris Alfano
 
Monitoring Your ISP Using InfluxDB Cloud and Raspberry Pi
Monitoring Your ISP Using InfluxDB Cloud and Raspberry PiMonitoring Your ISP Using InfluxDB Cloud and Raspberry Pi
Monitoring Your ISP Using InfluxDB Cloud and Raspberry Pi
InfluxData
 
Knockoutjs UG meeting presentation
Knockoutjs UG meeting presentationKnockoutjs UG meeting presentation
Knockoutjs UG meeting presentation
Valdis Iljuconoks
 
Refactoring to Macros with Clojure
Refactoring to Macros with ClojureRefactoring to Macros with Clojure
Refactoring to Macros with ClojureDmitry Buzdin
 
JavaScript on Rails 튜토리얼
JavaScript on Rails 튜토리얼JavaScript on Rails 튜토리얼
JavaScript on Rails 튜토리얼
Sukjoon Kim
 
Bonnes pratiques de développement avec Node js
Bonnes pratiques de développement avec Node jsBonnes pratiques de développement avec Node js
Bonnes pratiques de développement avec Node js
Francois Zaninotto
 
Cheap frontend tricks
Cheap frontend tricksCheap frontend tricks
Cheap frontend tricks
ambiescent
 
Svcc 2013-d3
Svcc 2013-d3Svcc 2013-d3
Svcc 2013-d3
Oswald Campesato
 
Taming that client side mess with Backbone.js
Taming that client side mess with Backbone.jsTaming that client side mess with Backbone.js
Taming that client side mess with Backbone.jsJarod Ferguson
 
Understanding backbonejs
Understanding backbonejsUnderstanding backbonejs
Understanding backbonejs
Nick Lee
 
jQuery
jQueryjQuery
Building Large jQuery Applications
Building Large jQuery ApplicationsBuilding Large jQuery Applications
Building Large jQuery Applications
Rebecca Murphey
 
Some Advanced Tracking in Google Analytics in 5 mins - PhillyJS meet up
Some Advanced Tracking in Google Analytics in 5 mins - PhillyJS meet up Some Advanced Tracking in Google Analytics in 5 mins - PhillyJS meet up
Some Advanced Tracking in Google Analytics in 5 mins - PhillyJS meet up Nico Miceli
 
mobl presentation @ IHomer
mobl presentation @ IHomermobl presentation @ IHomer
mobl presentation @ IHomerzefhemel
 
jQuery - 10 Time-Savers You (Maybe) Don't Know
jQuery - 10 Time-Savers You (Maybe) Don't KnowjQuery - 10 Time-Savers You (Maybe) Don't Know
jQuery - 10 Time-Savers You (Maybe) Don't Knowgirish82
 

Similar to JQuery Flot (20)

Big Data for each one of us
Big Data for each one of usBig Data for each one of us
Big Data for each one of us
 
Modular and Event-Driven JavaScript
Modular and Event-Driven JavaScriptModular and Event-Driven JavaScript
Modular and Event-Driven JavaScript
 
jQuery: Tips, tricks and hints for better development and Performance
jQuery: Tips, tricks and hints for better development and PerformancejQuery: Tips, tricks and hints for better development and Performance
jQuery: Tips, tricks and hints for better development and Performance
 
Aplicacoes dinamicas Rails com Backbone
Aplicacoes dinamicas Rails com BackboneAplicacoes dinamicas Rails com Backbone
Aplicacoes dinamicas Rails com Backbone
 
Data visualization in python/Django
Data visualization in python/DjangoData visualization in python/Django
Data visualization in python/Django
 
Jarv.us Showcase — SenchaCon 2011
Jarv.us Showcase — SenchaCon 2011Jarv.us Showcase — SenchaCon 2011
Jarv.us Showcase — SenchaCon 2011
 
Monitoring Your ISP Using InfluxDB Cloud and Raspberry Pi
Monitoring Your ISP Using InfluxDB Cloud and Raspberry PiMonitoring Your ISP Using InfluxDB Cloud and Raspberry Pi
Monitoring Your ISP Using InfluxDB Cloud and Raspberry Pi
 
Knockoutjs UG meeting presentation
Knockoutjs UG meeting presentationKnockoutjs UG meeting presentation
Knockoutjs UG meeting presentation
 
Refactoring to Macros with Clojure
Refactoring to Macros with ClojureRefactoring to Macros with Clojure
Refactoring to Macros with Clojure
 
JavaScript on Rails 튜토리얼
JavaScript on Rails 튜토리얼JavaScript on Rails 튜토리얼
JavaScript on Rails 튜토리얼
 
Bonnes pratiques de développement avec Node js
Bonnes pratiques de développement avec Node jsBonnes pratiques de développement avec Node js
Bonnes pratiques de développement avec Node js
 
Cheap frontend tricks
Cheap frontend tricksCheap frontend tricks
Cheap frontend tricks
 
Svcc 2013-d3
Svcc 2013-d3Svcc 2013-d3
Svcc 2013-d3
 
Taming that client side mess with Backbone.js
Taming that client side mess with Backbone.jsTaming that client side mess with Backbone.js
Taming that client side mess with Backbone.js
 
Understanding backbonejs
Understanding backbonejsUnderstanding backbonejs
Understanding backbonejs
 
jQuery
jQueryjQuery
jQuery
 
Building Large jQuery Applications
Building Large jQuery ApplicationsBuilding Large jQuery Applications
Building Large jQuery Applications
 
Some Advanced Tracking in Google Analytics in 5 mins - PhillyJS meet up
Some Advanced Tracking in Google Analytics in 5 mins - PhillyJS meet up Some Advanced Tracking in Google Analytics in 5 mins - PhillyJS meet up
Some Advanced Tracking in Google Analytics in 5 mins - PhillyJS meet up
 
mobl presentation @ IHomer
mobl presentation @ IHomermobl presentation @ IHomer
mobl presentation @ IHomer
 
jQuery - 10 Time-Savers You (Maybe) Don't Know
jQuery - 10 Time-Savers You (Maybe) Don't KnowjQuery - 10 Time-Savers You (Maybe) Don't Know
jQuery - 10 Time-Savers You (Maybe) Don't Know
 

Recently uploaded

FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdfFIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance
 
IOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptx
IOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptxIOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptx
IOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptx
Abida Shariff
 
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdfFIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance
 
The Future of Platform Engineering
The Future of Platform EngineeringThe Future of Platform Engineering
The Future of Platform Engineering
Jemma Hussein Allen
 
Neuro-symbolic is not enough, we need neuro-*semantic*
Neuro-symbolic is not enough, we need neuro-*semantic*Neuro-symbolic is not enough, we need neuro-*semantic*
Neuro-symbolic is not enough, we need neuro-*semantic*
Frank van Harmelen
 
ODC, Data Fabric and Architecture User Group
ODC, Data Fabric and Architecture User GroupODC, Data Fabric and Architecture User Group
ODC, Data Fabric and Architecture User Group
CatarinaPereira64715
 
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Product School
 
DevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA ConnectDevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA Connect
Kari Kakkonen
 
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdfFIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance
 
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
Product School
 
UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3
DianaGray10
 
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
BookNet Canada
 
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
Product School
 
Connector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a buttonConnector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a button
DianaGray10
 
GraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge GraphGraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge Graph
Guy Korland
 
Essentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with ParametersEssentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with Parameters
Safe Software
 
JMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and GrafanaJMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and Grafana
RTTS
 
When stars align: studies in data quality, knowledge graphs, and machine lear...
When stars align: studies in data quality, knowledge graphs, and machine lear...When stars align: studies in data quality, knowledge graphs, and machine lear...
When stars align: studies in data quality, knowledge graphs, and machine lear...
Elena Simperl
 
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Jeffrey Haguewood
 
Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........
Alison B. Lowndes
 

Recently uploaded (20)

FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdfFIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
 
IOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptx
IOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptxIOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptx
IOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptx
 
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdfFIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
 
The Future of Platform Engineering
The Future of Platform EngineeringThe Future of Platform Engineering
The Future of Platform Engineering
 
Neuro-symbolic is not enough, we need neuro-*semantic*
Neuro-symbolic is not enough, we need neuro-*semantic*Neuro-symbolic is not enough, we need neuro-*semantic*
Neuro-symbolic is not enough, we need neuro-*semantic*
 
ODC, Data Fabric and Architecture User Group
ODC, Data Fabric and Architecture User GroupODC, Data Fabric and Architecture User Group
ODC, Data Fabric and Architecture User Group
 
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
 
DevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA ConnectDevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA Connect
 
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdfFIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
 
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
 
UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3
 
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
 
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
 
Connector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a buttonConnector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a button
 
GraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge GraphGraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge Graph
 
Essentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with ParametersEssentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with Parameters
 
JMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and GrafanaJMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and Grafana
 
When stars align: studies in data quality, knowledge graphs, and machine lear...
When stars align: studies in data quality, knowledge graphs, and machine lear...When stars align: studies in data quality, knowledge graphs, and machine lear...
When stars align: studies in data quality, knowledge graphs, and machine lear...
 
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
 
Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........
 

JQuery Flot

  • 1. JQuery Flot by Arshavski Alexander
  • 2. Charting libraries A lot of choices - http://my.opera.com/tagawa/blog/list-of-javascript-ch
  • 3.
  • 4. Good list of features http://socialcompare.com/en/comparison/javascript-g
  • 5. Should work offline
  • 7. ...
  • 8. Flot works on: Firefox 2.x+ Safari 3.0+ Opera 9.5+ Konqueror 4.x+ Internet Explorer 6+ (the excanvas Javascript emulation helper is used for IE < 9)
  • 9. A lot of plugins and examples Plugins - http://code.google.com/p/flot/wiki/Plugins Bubble charts - https://github.com/ubermajestix/flot-plugins Usage examples: http://code.google.com/p/flot/wiki/FlotUsage
  • 10. It’s not all pink and rosy Documentation sucks!
  • 12. What I want to do?
  • 13. What I want to do?
  • 14. What I want to do?
  • 15. Imports <link type="text/css" href="...jquery-ui.css"> <link type="text/css" href="...flot_layout.css" > <link type="text/css" href="...jquery-ui-1.8.16.custom.css"> <script type="text/javascript" src="...jquery-1.5.1.min.js"></script> <script type="text/javascript" src="...jquery-ui-1.8.10.custom.min.js"></script> <script type="text/javascript" src="...jquery.flot.min.js"></script> <script type="text/javascript" src="...jquery.flot.pie.min.js"></script> <script type="text/javascript" src="...jquery.blockUI.js"></script>
  • 16. Radio buttons <div id="radio"> <input type="radio" id="connections_radio" name="radio" checked="checked" /><label for="connections_radio">Connections</label> <input type="radio" id="usage_radio" name="radio" /><label for="usage_radio">Usage</label> <input type="radio" id="export_radio" name="radio" /><label for="export_radio">Export</label> </div>
  • 17. Tabs <div id="usage" style="display: none"> <div id="usage_tabs"> <ul> <li><a href="#day_statistics">Day</a></li> <li><a href="#week_statistics">Week</a></li> <li><a href="#month_statistics">Month</a></li> <li><a href="#year_statistics">Year</a></li> </ul> <div id="day_statistics"> <div id="graphs_container1" class="graph_container”> <div id="graph1"></div> <div id="graph1_legend" class="graph_legend"></div> </div> </div> ... </div> ... </div>
  • 18. Radio buttons $(function () { $("#connections_radio").click(function(event) { $("#connections").show(); $("#usage").hide(); $("#export").hide(); }); $("#usage_radio").click(function(event) { $("#connections").hide(); $("#usage").show(); $("#export").hide(); }); $("#export_radio").click(function(event) { $("#connections").hide(); $("#usage").hide(); $("#export").show(); }); });
  • 19. Tabs $(function () { ... $("#connections_tabs").tabs(); $("#usage_tabs").tabs(); $("#usage_distribution_tabs").tabs(); });
  • 21. As a python guy it’s a lot of code for me already, so it’s gonna be a mess
  • 22. Refactoring <script type="text/javascript" src="...statistics.js"></script> $(function () { ... get_connections_statistics(); get_usage_statistics(); get_api_distribution_statistics(); get_distribution_statistics(); ... }); {% include "statistics/connections.html" %} {% include "statistics/usage.html" %} {% include "statistics/export.html" %}
  • 23. And now to the main part... var weekdayNames = "Sunday Monday Tuesday Wednesday Thursday Friday Saturday".split(" "); var shortMonthNames = "Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec".split(" "); $.get('/manage/get_statistics_usage_data', {}, function(data){ var stat_data = jQuery.parseJSON(data); //variables init var now = new Date().getTime() + stat_data.time_offset; var weekday = new Date(now).getDay(); var month = new Date(now).getMonth(); ...
  • 24. And now to the main part... //building weekly data var api_calls_points = stat_data.api_calls_weekly; var bandwidth_points = stat_data.bandwidth_weekly; for(var i=0; i<api_calls_points.length; i++) { graph2_ticks.push([7-i, weekdayNames[(weekday+7-i)%7]]); api_calls_weekly.push([i, api_calls_points[i]]); bandwidth_weekly.push([i, bandwidth_points[i]]); } ... //building yearly data var api_calls_points = stat_data.api_calls_yearly; var bandwidth_points = stat_data.bandwidth_yearly; for(var i=0; i<api_calls_points.length; i++) { graph4_ticks.push([12-i, shortMonthNames[(month+12-i)%12]]); api_calls_yearly.push([i, api_calls_points[i]]); bandwidth_yearly.push([i, bandwidth_points[i]]); }
  • 25. And now to the main part... var options2 = { legend: { position: "ne", container: $("#graph2_legend") }, xaxis: { ticks: graph2_ticks }, yaxis: { min: 0, tickDecimals: 0 //only whole numbers }, grid: { hoverable: true } }; xaxis: { //in case of time axis mode: "time", timeformat: "%H:%M" },
  • 26. And now to the main part... var usage_plot2 = $.plot($("#graph2"), [ { data: api_calls_weekly, label: "API calls", lines: { show: true } }, { label: "Bandwidth (KB)", data: bandwidth_weekly, lines: { show: true } }, ], options2);
  • 28. What if I want to select a graph?
  • 29. Graph Select $('.legendColorBox').parent().click(function() { var plot = usage_plot1; var data = [api_calls_daily, bandwidth_daily]; var graph = $(this).parent().parent().parent().attr("id").split("_")[0]; if (graph == "graph2") { plot = usage_plot2; data = [api_calls_weekly, bandwidth_weekly]; } ... if ($(this).children().text() == "API calls”) { plot.setData(get_plot_data([data[0], null, "lines", [], null, "lines"])); } if ($(this).children().text() == "Bandwidth (KB)") { plot.setData(get_plot_data([[], null, "lines", data[1], null, "lines"])); } plot.draw(); ...
  • 30. Graph Select var ticks = [graph2_ticks, graph3_ticks, graph4_ticks]; if ($(this).siblings().text().search("Show all") == -1) { $('<tr/>', { style: 'cursor: auto;' }).bind('click', {plot: plot, data: data, ticks: ticks, now: now}, show_all_usage_graphs) .append("<td class='legendColorBox'></td><td>Show all</td>").appendTo($ (this).parent()); } }); function show_all_usage_graphs(e) { e.data.plot.setData(get_plot_data([e.data.data[0], null, "lines", e.data.data[1], null, "lines"])); e.data.plot.draw(); $(this).remove(); }
  • 32. What about tooltips? I could take them from a lot of places. For example: http://jquerytools.org/
  • 33. I decided to do it myself
  • 34. Tooltips function add_usage_tooltips(now, ticks) { for (var i=1; i<=4; i++) { ... $("#graph" + i).bind("plothover", function (event, pos, item) { draw_tooltip(item, tick, now); }); } } function draw_tooltip(item, ticks, now) { ... var tooltip = get_tooltip_message(item, ticks, now); showChartTooltip(tooltip, item); ... }
  • 35. Tooltips function showChartTooltip(contents, item) { ... $("<div id='charttooltip'>" + contents + "</div>").css( { position: 'absolute', display: 'none', top: item.pageY + 5, left: item.pageX + 5, border: '1px solid #bfbfbf', padding: '2px', 'background-color': item.series.color, opacity: 1 }).appendTo("body").fadeIn(200); ... }
  • 37. How can I make bars? $.plot($("#graph2"), [ { data: api_calls_weekly, label: "Clients API hourly", bars: { show: true } //instead of: lines: { show: true } }, ... ], options2);
  • 38. By the way tooltips on bars looks good...
  • 39. For charts you should add: <script type="text/javascript" src="...jquery.flot.pie.min.js"></script>
  • 40. Charts var options = { series: { pie: { show: true, radius: 1, label: { show: true, radius: 3/4, formatter: function(label, series){ return '<div style="font-size:12pt;text- align:center;padding:2px;color:black;">'+label+'<br/>'+Math.round(series.percent)+'%</ div>'; }, background: { opacity: 0.5 } } } } }; $.plot($("#countries_piechart"), data, options);
  • 41. One last thing... JQuery BlockUI Plugin: http://jquery.malsup.com/block/
  • 42. BlockUI <script type="text/javascript" src="...jquery.blockUI.js"></script> $(function () { ... var message = '<img src=".../loader.gif" /> Please wait...'; $("#usage_tabs").block({ message: message }); ... get_usage_statistics(); ... } function get_usage_statistics() { $.get('.../get_statistics_usage_data', {}, function(data){ ... $("#usage_tabs").unblock(); }); }
  • 44. Questions? alexarsh5@gmail.com http://twitter.com/alexarsh http://www.linkedin.com/pub