SlideShare a Scribd company logo
IN THIS TUTORIAL, WE SHOWCASE
WHAT MORE CAN BE DONE WITH
D3.js and PUBNUB!
+
WHAT IS D3.JS?
• A JavaScript Library
• Lets you stream data to create interactive
graphs & charts that run in the browser
• A very powerful tool for creating eye-
catching data visualizations
TODAY…WE SHOWCASE WHAT YOU CAN DO
MORE WITH D3 & PUBNUB.
LET’S BEGIN AND GET MORE
VISUAL WITH A BUBBLE
CHART!
PREREQUISITES
• Basic to intermediate
knowledge of JavaScript
Document Object Model
(DOM)
• Basic understanding of
SVG and D3.js
STEPS WE’LL TAKE
In this tutorial, you will learn how to:
1. Create a static bubble chart using D3.js
2. Bind streaming JSON data to the chart
3. Live-update and animate the bubble chart
STEP #1
CREATE A STATIC BUBBLE CHART
TO GET STARTED…
Include d3.min.js in your HTML file, then define a layout.
STEP 1: CREATE A STATIC BUBBLE
CHART
1.1. Use D3.js’s Graphical Layout
To draw a bubble chart, we create a pack layout using
d3.layout.pack() object.
STEP 1: CREATE A STATIC BUBBLE
CHART
1.2. WORK WITH JSON DATA
1. Sign up for a PubNub account.
2. Get your unique PubNub keys in the PubNub Developer Portal.
3. Clone the GitHub repository, and enter your unique PubNub keys on
the PubNub initialization.
For now, we’ll use simulated data, which is similar to the actual streaming
JSON we will use in this tutorial. Assume the data came from our global data
centers, and each data set represents a country, and access volume from the
country.
STEP 1: CREATE A STATIC BUBBLE
CHART
1.2. WORK WITH JSON DATA
4. Customize this raw data to be used in the pack layout.
The pack layout is part of D3′s family of hierarchical layouts and by
default, D3 assumes that the input data is an object with a children
array, so it is convenient to return the object looks like,
{children: [an array of objects]}
STEP 1: CREATE A STATIC BUBBLE
CHART
1.2. WORK WITH JSON DATA
5. The className values are to be used to colorize each SVG circle by
country, defined in CSS.
STEP 1: CREATE A STATIC BUBBLE
CHART
1.3. ENTER DATA INTO THE LAYOUT
1. We are loading the tailored data into layout object’s nodes()
function, which automagically populates graphical data (size of
each circle and positions) with a set of standard attributes, so all
the circles will nicely fit in a chart.
2. Then, use the generated layout calculations to display in SVG.
AWESOME!
YOU’VE CREATED A BUBBLE CHART!
JUST A FEW MORE STEPS…
STEP #2
MAKE D3.JS DYNAMIC WITH
STREAMING JSON
WE ARE READY TO REPLACE THE STATIC JSON
WITH LIVE JSON FROM PUBNUB DATA STREAMS
STEP 2: MAKE D3.js DYNAMIC WITH
STREAMING JSON
• Include the PubNub JavaScript libraries in your HTML to begin
(You’ll first need to sign up for a PubNub account. Once you
sign up, you can get your unique PubNub keys in the PubNub
Developer Portal).
• We are using a chunk of predefined set of data here for the
exercise, so let’s initialize the API with the existing channel.
STEP 2: MAKE D3.js DYNAMIC WITH
STREAMING JSON
2.1. SUBSCRIBE THE LIVE DATA
1. To retrieve the live data, you simply use PubNub subscribe()
API.
2. Once you successfully retrieve the data from the stream, call
the callback function to draw the chart.
NOW, EVERY TIME A NEW SET OF DATA COMES,
NEW BUBBLES ARE DISPLAYED!
HOWEVER, THEY KEEP BEING ADDED ON TOP OF THE
PREVIOUS CHART. THIS LOOKS PRETTY FUNKY, BUT IT IS
NOT WHAT WE WANT! WE NEED TO FIX THIS.
STEP #3
LIVE-UPDATE & ANIMATE THE
BUBBLES!
OK, let’s bind data to elements correctly!
STEP 3: LIVE-UPDATE & ANIMATE THE
BUBBLES!
3.1. ASSIGN EACH NODE WITH A UNIQUE NAME
D3 uses the enter, update, and exit pattern to join data to DOM.
At the previous step 1.3, you have enter() the initial data. To make
the node updateable, you need to assign a name to each node. D3
takes a key function as a second argument to the data() method.
Modify the code to assign a unique field name:
STEP 3: LIVE-UPDATE & ANIMATE THE
BUBBLES!
3.2. CREATE CHAINED TRANSISTIONS
• Also, at the step 1.3, we celled data(), enter() and append()
sequentially.
• To enter new data to the existing nodes, we are going to
update them. This way, each assigned bubble circle updates
its size and position correctly, instead of creating a new one
with new data.
STEP 3: LIVE-UPDATE & ANIMATE THE
BUBBLES!
3.2. CREATE CHAINED TRANSISTIONS
To make smooth transitions between old and new data, apply a
transition only to the updating nodes, and not entering nodes. The trick is to
create the transition on the updating elements before the entering elements
because enter().append() merges entering elements into the update
selection.
1 2 3
STEP 3: LIVE-UPDATE & ANIMATE THE
BUBBLES!
3.2. CREATE CHAINED TRANSISTIONS
Note: Some bubbles may be a null in upcoming data set,
and need to be removed. We use exit() and remove(). Also
giving an opacity (1 to 0) transition to create a complete
sequence of chained transitions.
STEP 3: LIVE-UPDATE & ANIMATE THE
BUBBLES!
3.2. CREATE CHAINED TRANSISTIONS
In this example, we are
transitioning the position and
radius of each bubble upon
updating the data, also opacity
upon entering and exiting.
Moreover, with using delay
method along with transition, we
are making the animation effect
more interesting. Tweak the
values and see what works the
best.
Fun with D3js: Data Visualization Eye Candy with Streaming JSON
More PubNub Visualization Tutorials
www.PubNub.com
FOR MORE INFO

More Related Content

What's hot

Qlikアプリケーションのパフォーマンス最適化戦略
Qlikアプリケーションのパフォーマンス最適化戦略Qlikアプリケーションのパフォーマンス最適化戦略
Qlikアプリケーションのパフォーマンス最適化戦略
QlikPresalesJapan
 
Multivariate Data Visualization
Multivariate Data VisualizationMultivariate Data Visualization
Multivariate Data Visualizationanilash
 
Suppressing http headers from web sphere application server
Suppressing http headers from web sphere application serverSuppressing http headers from web sphere application server
Suppressing http headers from web sphere application serverDave Hay
 
Deep dive into PostgreSQL statistics.
Deep dive into PostgreSQL statistics.Deep dive into PostgreSQL statistics.
Deep dive into PostgreSQL statistics.
Alexey Lesovsky
 
Efficient Data Storage for Analytics with Parquet 2.0 - Hadoop Summit 2014
Efficient Data Storage for Analytics with Parquet 2.0 - Hadoop Summit 2014Efficient Data Storage for Analytics with Parquet 2.0 - Hadoop Summit 2014
Efficient Data Storage for Analytics with Parquet 2.0 - Hadoop Summit 2014
Julien Le Dem
 
Data Access Patterns
Data Access PatternsData Access Patterns
Data Access Patterns
Amazon Web Services
 
PostgreSQL : Introduction
PostgreSQL : IntroductionPostgreSQL : Introduction
PostgreSQL : Introduction
Open Source School
 

What's hot (7)

Qlikアプリケーションのパフォーマンス最適化戦略
Qlikアプリケーションのパフォーマンス最適化戦略Qlikアプリケーションのパフォーマンス最適化戦略
Qlikアプリケーションのパフォーマンス最適化戦略
 
Multivariate Data Visualization
Multivariate Data VisualizationMultivariate Data Visualization
Multivariate Data Visualization
 
Suppressing http headers from web sphere application server
Suppressing http headers from web sphere application serverSuppressing http headers from web sphere application server
Suppressing http headers from web sphere application server
 
Deep dive into PostgreSQL statistics.
Deep dive into PostgreSQL statistics.Deep dive into PostgreSQL statistics.
Deep dive into PostgreSQL statistics.
 
Efficient Data Storage for Analytics with Parquet 2.0 - Hadoop Summit 2014
Efficient Data Storage for Analytics with Parquet 2.0 - Hadoop Summit 2014Efficient Data Storage for Analytics with Parquet 2.0 - Hadoop Summit 2014
Efficient Data Storage for Analytics with Parquet 2.0 - Hadoop Summit 2014
 
Data Access Patterns
Data Access PatternsData Access Patterns
Data Access Patterns
 
PostgreSQL : Introduction
PostgreSQL : IntroductionPostgreSQL : Introduction
PostgreSQL : Introduction
 

Viewers also liked

HiTech Manufacturing Use Cases/Examples
HiTech Manufacturing Use Cases/ExamplesHiTech Manufacturing Use Cases/Examples
HiTech Manufacturing Use Cases/Examples
TIBCO Spotfire
 
Global Data Stream Network for Internet of Things
Global Data Stream Network for Internet of ThingsGlobal Data Stream Network for Internet of Things
Global Data Stream Network for Internet of Things
Bhavana Srinivas
 
flowspec @ APF 2013
flowspec @ APF 2013flowspec @ APF 2013
flowspec @ APF 2013Tom Paseka
 
OpenLayers vs. Leaflet
OpenLayers vs. LeafletOpenLayers vs. Leaflet
OpenLayers vs. Leaflet
dasjo
 
Websocket + Redis pubsub
Websocket + Redis pubsubWebsocket + Redis pubsub
Websocket + Redis pubsub
Kai Hsu
 
Real time web: is there a life without socket.io and node.js?
Real time web: is there a life without socket.io and node.js?Real time web: is there a life without socket.io and node.js?
Real time web: is there a life without socket.io and node.js?
Eduard Trayan
 
Going real time with Socket.io
Going real time with Socket.ioGoing real time with Socket.io
Going real time with Socket.io
Arnout Kazemier
 
RedisConf 2016 - Redis usage and ecosystem
RedisConf 2016 - Redis usage and ecosystemRedisConf 2016 - Redis usage and ecosystem
RedisConf 2016 - Redis usage and ecosystem
François-Guillaume Ribreau
 
Set Your Course for Change with Real-Time Analytics and Insights
Set Your Course for Change with Real-Time Analytics and InsightsSet Your Course for Change with Real-Time Analytics and Insights
Set Your Course for Change with Real-Time Analytics and Insights
TIBCO Software Inc.
 
Building notification system in NodeJS + Redis
Building notification system in NodeJS + RedisBuilding notification system in NodeJS + Redis
Building notification system in NodeJS + RedisLe Duc
 
Real Time Communication using Node.js and Socket.io
Real Time Communication using Node.js and Socket.ioReal Time Communication using Node.js and Socket.io
Real Time Communication using Node.js and Socket.io
Mindfire Solutions
 
Running Analytics at the Speed of Your Business
Running Analytics at the Speed of Your BusinessRunning Analytics at the Speed of Your Business
Running Analytics at the Speed of Your Business
Redis Labs
 
Going realtime with Socket.IO
Going realtime with Socket.IOGoing realtime with Socket.IO
Going realtime with Socket.IO
Christian Joudrey
 
Redis Networking Nerd Down: For Lovers of Packets and Jumbo Frames- John Bull...
Redis Networking Nerd Down: For Lovers of Packets and Jumbo Frames- John Bull...Redis Networking Nerd Down: For Lovers of Packets and Jumbo Frames- John Bull...
Redis Networking Nerd Down: For Lovers of Packets and Jumbo Frames- John Bull...
Redis Labs
 
Day 1 General Session RedisConf
Day 1 General Session RedisConfDay 1 General Session RedisConf
Day 1 General Session RedisConf
Redis Labs
 
Monitoring and Scaling Redis at DataDog - Ilan Rabinovitch, DataDog
 Monitoring and Scaling Redis at DataDog - Ilan Rabinovitch, DataDog Monitoring and Scaling Redis at DataDog - Ilan Rabinovitch, DataDog
Monitoring and Scaling Redis at DataDog - Ilan Rabinovitch, DataDog
Redis Labs
 
Real-time Web Application with Socket.IO, Node.js, and Redis
Real-time Web Application with Socket.IO, Node.js, and RedisReal-time Web Application with Socket.IO, Node.js, and Redis
Real-time Web Application with Socket.IO, Node.js, and Redis
York Tsai
 
Real Time Recommendations Using WebSockets and Redis - Ninad Divadkar, Inuit
Real Time Recommendations Using WebSockets and Redis - Ninad Divadkar, InuitReal Time Recommendations Using WebSockets and Redis - Ninad Divadkar, Inuit
Real Time Recommendations Using WebSockets and Redis - Ninad Divadkar, Inuit
Redis Labs
 
Scaling Redis Cluster Deployments for Genome Analysis (featuring LSU) - Terry...
Scaling Redis Cluster Deployments for Genome Analysis (featuring LSU) - Terry...Scaling Redis Cluster Deployments for Genome Analysis (featuring LSU) - Terry...
Scaling Redis Cluster Deployments for Genome Analysis (featuring LSU) - Terry...
Redis Labs
 
High-Volume Data Collection and Real Time Analytics Using Redis
High-Volume Data Collection and Real Time Analytics Using RedisHigh-Volume Data Collection and Real Time Analytics Using Redis
High-Volume Data Collection and Real Time Analytics Using Redis
cacois
 

Viewers also liked (20)

HiTech Manufacturing Use Cases/Examples
HiTech Manufacturing Use Cases/ExamplesHiTech Manufacturing Use Cases/Examples
HiTech Manufacturing Use Cases/Examples
 
Global Data Stream Network for Internet of Things
Global Data Stream Network for Internet of ThingsGlobal Data Stream Network for Internet of Things
Global Data Stream Network for Internet of Things
 
flowspec @ APF 2013
flowspec @ APF 2013flowspec @ APF 2013
flowspec @ APF 2013
 
OpenLayers vs. Leaflet
OpenLayers vs. LeafletOpenLayers vs. Leaflet
OpenLayers vs. Leaflet
 
Websocket + Redis pubsub
Websocket + Redis pubsubWebsocket + Redis pubsub
Websocket + Redis pubsub
 
Real time web: is there a life without socket.io and node.js?
Real time web: is there a life without socket.io and node.js?Real time web: is there a life without socket.io and node.js?
Real time web: is there a life without socket.io and node.js?
 
Going real time with Socket.io
Going real time with Socket.ioGoing real time with Socket.io
Going real time with Socket.io
 
RedisConf 2016 - Redis usage and ecosystem
RedisConf 2016 - Redis usage and ecosystemRedisConf 2016 - Redis usage and ecosystem
RedisConf 2016 - Redis usage and ecosystem
 
Set Your Course for Change with Real-Time Analytics and Insights
Set Your Course for Change with Real-Time Analytics and InsightsSet Your Course for Change with Real-Time Analytics and Insights
Set Your Course for Change with Real-Time Analytics and Insights
 
Building notification system in NodeJS + Redis
Building notification system in NodeJS + RedisBuilding notification system in NodeJS + Redis
Building notification system in NodeJS + Redis
 
Real Time Communication using Node.js and Socket.io
Real Time Communication using Node.js and Socket.ioReal Time Communication using Node.js and Socket.io
Real Time Communication using Node.js and Socket.io
 
Running Analytics at the Speed of Your Business
Running Analytics at the Speed of Your BusinessRunning Analytics at the Speed of Your Business
Running Analytics at the Speed of Your Business
 
Going realtime with Socket.IO
Going realtime with Socket.IOGoing realtime with Socket.IO
Going realtime with Socket.IO
 
Redis Networking Nerd Down: For Lovers of Packets and Jumbo Frames- John Bull...
Redis Networking Nerd Down: For Lovers of Packets and Jumbo Frames- John Bull...Redis Networking Nerd Down: For Lovers of Packets and Jumbo Frames- John Bull...
Redis Networking Nerd Down: For Lovers of Packets and Jumbo Frames- John Bull...
 
Day 1 General Session RedisConf
Day 1 General Session RedisConfDay 1 General Session RedisConf
Day 1 General Session RedisConf
 
Monitoring and Scaling Redis at DataDog - Ilan Rabinovitch, DataDog
 Monitoring and Scaling Redis at DataDog - Ilan Rabinovitch, DataDog Monitoring and Scaling Redis at DataDog - Ilan Rabinovitch, DataDog
Monitoring and Scaling Redis at DataDog - Ilan Rabinovitch, DataDog
 
Real-time Web Application with Socket.IO, Node.js, and Redis
Real-time Web Application with Socket.IO, Node.js, and RedisReal-time Web Application with Socket.IO, Node.js, and Redis
Real-time Web Application with Socket.IO, Node.js, and Redis
 
Real Time Recommendations Using WebSockets and Redis - Ninad Divadkar, Inuit
Real Time Recommendations Using WebSockets and Redis - Ninad Divadkar, InuitReal Time Recommendations Using WebSockets and Redis - Ninad Divadkar, Inuit
Real Time Recommendations Using WebSockets and Redis - Ninad Divadkar, Inuit
 
Scaling Redis Cluster Deployments for Genome Analysis (featuring LSU) - Terry...
Scaling Redis Cluster Deployments for Genome Analysis (featuring LSU) - Terry...Scaling Redis Cluster Deployments for Genome Analysis (featuring LSU) - Terry...
Scaling Redis Cluster Deployments for Genome Analysis (featuring LSU) - Terry...
 
High-Volume Data Collection and Real Time Analytics Using Redis
High-Volume Data Collection and Real Time Analytics Using RedisHigh-Volume Data Collection and Real Time Analytics Using Redis
High-Volume Data Collection and Real Time Analytics Using Redis
 

Similar to Streaming and Visualizing Data with D3.js

Fun with D3.js: Data Visualization Eye Candy with Streaming JSON
Fun with D3.js: Data Visualization Eye Candy with Streaming JSONFun with D3.js: Data Visualization Eye Candy with Streaming JSON
Fun with D3.js: Data Visualization Eye Candy with Streaming JSON
Tomomi Imura
 
SAP BW - Info cube
SAP BW - Info cubeSAP BW - Info cube
SAP BW - Info cube
Yasmin Ashraf
 
D3 Mapping Visualization
D3 Mapping VisualizationD3 Mapping Visualization
D3 Mapping Visualization
Sudhir Chowbina
 
Deep Style: Using Variational Auto-encoders for Image Generation
Deep Style: Using Variational Auto-encoders for Image GenerationDeep Style: Using Variational Auto-encoders for Image Generation
Deep Style: Using Variational Auto-encoders for Image Generation
TJ Torres
 
Plan601 e session 2 demo
Plan601 e session 2 demoPlan601 e session 2 demo
Plan601 e session 2 demo
rkottam
 
Plan601 e session 2 demo
Plan601 e session 2 demoPlan601 e session 2 demo
Plan601 e session 2 demo
rkottam
 
Cis247 a ilab 3 overloaded methods and static methods variables
Cis247 a ilab 3 overloaded methods and static methods variablesCis247 a ilab 3 overloaded methods and static methods variables
Cis247 a ilab 3 overloaded methods and static methods variablesccis224477
 
Cis247 i lab 3 overloaded methods and static methods variables
Cis247 i lab 3 overloaded methods and static methods variablesCis247 i lab 3 overloaded methods and static methods variables
Cis247 i lab 3 overloaded methods and static methods variablessdjdskjd9097
 
Plan601 e session 2 demo
Plan601 e session 2 demoPlan601 e session 2 demo
Plan601 e session 2 demo
rkottam
 
Plan601 e session 2 demo
Plan601 e session 2 demoPlan601 e session 2 demo
Plan601 e session 2 demo
rkottam
 
Big data analytics project report
Big data analytics project reportBig data analytics project report
Big data analytics project report
Manav Deshmukh
 
Plan601 e session 2 demo
Plan601 e session 2 demoPlan601 e session 2 demo
Plan601 e session 2 demo
rkottam
 
Cis247 a ilab 3 overloaded methods and static methods variables
Cis247 a ilab 3 overloaded methods and static methods variablesCis247 a ilab 3 overloaded methods and static methods variables
Cis247 a ilab 3 overloaded methods and static methods variablescis247
 
Learn D3.js in 90 minutes
Learn D3.js in 90 minutesLearn D3.js in 90 minutes
Learn D3.js in 90 minutes
Jos Dirksen
 
Using QLIK with AWS & Python
Using QLIK with AWS & PythonUsing QLIK with AWS & Python
Using QLIK with AWS & Python
Bruce Jenks
 
How to empower community by using GIS lecture 2
How to empower community by using GIS lecture 2How to empower community by using GIS lecture 2
How to empower community by using GIS lecture 2wang yaohui
 
Sample Questions The following sample questions are not in.docx
Sample Questions The following sample questions are not in.docxSample Questions The following sample questions are not in.docx
Sample Questions The following sample questions are not in.docx
todd331
 
plan601 e session 2 demo
plan601 e session 2 demoplan601 e session 2 demo
plan601 e session 2 demorkottam
 

Similar to Streaming and Visualizing Data with D3.js (20)

Fun with D3.js: Data Visualization Eye Candy with Streaming JSON
Fun with D3.js: Data Visualization Eye Candy with Streaming JSONFun with D3.js: Data Visualization Eye Candy with Streaming JSON
Fun with D3.js: Data Visualization Eye Candy with Streaming JSON
 
SAP BW - Info cube
SAP BW - Info cubeSAP BW - Info cube
SAP BW - Info cube
 
D3 Mapping Visualization
D3 Mapping VisualizationD3 Mapping Visualization
D3 Mapping Visualization
 
Deep Style: Using Variational Auto-encoders for Image Generation
Deep Style: Using Variational Auto-encoders for Image GenerationDeep Style: Using Variational Auto-encoders for Image Generation
Deep Style: Using Variational Auto-encoders for Image Generation
 
Plan601E Session 2 Demo
Plan601E Session 2 DemoPlan601E Session 2 Demo
Plan601E Session 2 Demo
 
Plan601 e session 2 demo
Plan601 e session 2 demoPlan601 e session 2 demo
Plan601 e session 2 demo
 
Plan601 e session 2 demo
Plan601 e session 2 demoPlan601 e session 2 demo
Plan601 e session 2 demo
 
Cis247 a ilab 3 overloaded methods and static methods variables
Cis247 a ilab 3 overloaded methods and static methods variablesCis247 a ilab 3 overloaded methods and static methods variables
Cis247 a ilab 3 overloaded methods and static methods variables
 
Cis247 i lab 3 overloaded methods and static methods variables
Cis247 i lab 3 overloaded methods and static methods variablesCis247 i lab 3 overloaded methods and static methods variables
Cis247 i lab 3 overloaded methods and static methods variables
 
Plan601 e session 2 demo
Plan601 e session 2 demoPlan601 e session 2 demo
Plan601 e session 2 demo
 
Plan601E Session 2 Demo
Plan601E Session 2 DemoPlan601E Session 2 Demo
Plan601E Session 2 Demo
 
Plan601 e session 2 demo
Plan601 e session 2 demoPlan601 e session 2 demo
Plan601 e session 2 demo
 
Big data analytics project report
Big data analytics project reportBig data analytics project report
Big data analytics project report
 
Plan601 e session 2 demo
Plan601 e session 2 demoPlan601 e session 2 demo
Plan601 e session 2 demo
 
Cis247 a ilab 3 overloaded methods and static methods variables
Cis247 a ilab 3 overloaded methods and static methods variablesCis247 a ilab 3 overloaded methods and static methods variables
Cis247 a ilab 3 overloaded methods and static methods variables
 
Learn D3.js in 90 minutes
Learn D3.js in 90 minutesLearn D3.js in 90 minutes
Learn D3.js in 90 minutes
 
Using QLIK with AWS & Python
Using QLIK with AWS & PythonUsing QLIK with AWS & Python
Using QLIK with AWS & Python
 
How to empower community by using GIS lecture 2
How to empower community by using GIS lecture 2How to empower community by using GIS lecture 2
How to empower community by using GIS lecture 2
 
Sample Questions The following sample questions are not in.docx
Sample Questions The following sample questions are not in.docxSample Questions The following sample questions are not in.docx
Sample Questions The following sample questions are not in.docx
 
plan601 e session 2 demo
plan601 e session 2 demoplan601 e session 2 demo
plan601 e session 2 demo
 

More from PubNub

Defining the IoT Stack
Defining the IoT StackDefining the IoT Stack
Defining the IoT Stack
PubNub
 
What the heck is a realtime app?
What the heck is a realtime app?What the heck is a realtime app?
What the heck is a realtime app?
PubNub
 
TrackPad Destroyer
TrackPad DestroyerTrackPad Destroyer
TrackPad Destroyer
PubNub
 
Real-Time Stats for Candy Box
Real-Time Stats for Candy Box  Real-Time Stats for Candy Box
Real-Time Stats for Candy Box
PubNub
 
Streaming Geo Coordinates from MongoDB to your iPhone App with PubNub using W...
Streaming Geo Coordinates from MongoDB to your iPhone App with PubNub using W...Streaming Geo Coordinates from MongoDB to your iPhone App with PubNub using W...
Streaming Geo Coordinates from MongoDB to your iPhone App with PubNub using W...PubNub
 
Lightweight Multiplayer HTML5 Games with PubNub
Lightweight Multiplayer HTML5 Games with PubNubLightweight Multiplayer HTML5 Games with PubNub
Lightweight Multiplayer HTML5 Games with PubNub
PubNub
 

More from PubNub (6)

Defining the IoT Stack
Defining the IoT StackDefining the IoT Stack
Defining the IoT Stack
 
What the heck is a realtime app?
What the heck is a realtime app?What the heck is a realtime app?
What the heck is a realtime app?
 
TrackPad Destroyer
TrackPad DestroyerTrackPad Destroyer
TrackPad Destroyer
 
Real-Time Stats for Candy Box
Real-Time Stats for Candy Box  Real-Time Stats for Candy Box
Real-Time Stats for Candy Box
 
Streaming Geo Coordinates from MongoDB to your iPhone App with PubNub using W...
Streaming Geo Coordinates from MongoDB to your iPhone App with PubNub using W...Streaming Geo Coordinates from MongoDB to your iPhone App with PubNub using W...
Streaming Geo Coordinates from MongoDB to your iPhone App with PubNub using W...
 
Lightweight Multiplayer HTML5 Games with PubNub
Lightweight Multiplayer HTML5 Games with PubNubLightweight Multiplayer HTML5 Games with PubNub
Lightweight Multiplayer HTML5 Games with PubNub
 

Recently uploaded

LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
DanBrown980551
 
Removing Uninteresting Bytes in Software Fuzzing
Removing Uninteresting Bytes in Software FuzzingRemoving Uninteresting Bytes in Software Fuzzing
Removing Uninteresting Bytes in Software Fuzzing
Aftab Hussain
 
Le nuove frontiere dell'AI nell'RPA con UiPath Autopilot™
Le nuove frontiere dell'AI nell'RPA con UiPath Autopilot™Le nuove frontiere dell'AI nell'RPA con UiPath Autopilot™
Le nuove frontiere dell'AI nell'RPA con UiPath Autopilot™
UiPathCommunity
 
Introduction to CHERI technology - Cybersecurity
Introduction to CHERI technology - CybersecurityIntroduction to CHERI technology - Cybersecurity
Introduction to CHERI technology - Cybersecurity
mikeeftimakis1
 
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
UiPathCommunity
 
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
 
zkStudyClub - Reef: Fast Succinct Non-Interactive Zero-Knowledge Regex Proofs
zkStudyClub - Reef: Fast Succinct Non-Interactive Zero-Knowledge Regex ProofszkStudyClub - Reef: Fast Succinct Non-Interactive Zero-Knowledge Regex Proofs
zkStudyClub - Reef: Fast Succinct Non-Interactive Zero-Knowledge Regex Proofs
Alex Pruden
 
Assure Contact Center Experiences for Your Customers With ThousandEyes
Assure Contact Center Experiences for Your Customers With ThousandEyesAssure Contact Center Experiences for Your Customers With ThousandEyes
Assure Contact Center Experiences for Your Customers With ThousandEyes
ThousandEyes
 
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
 
Monitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR EventsMonitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR Events
Ana-Maria Mihalceanu
 
Elizabeth Buie - Older adults: Are we really designing for our future selves?
Elizabeth Buie - Older adults: Are we really designing for our future selves?Elizabeth Buie - Older adults: Are we really designing for our future selves?
Elizabeth Buie - Older adults: Are we really designing for our future selves?
Nexer Digital
 
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
 
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
 
PCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase TeamPCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase Team
ControlCase
 
Epistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI supportEpistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI support
Alan Dix
 
The Metaverse and AI: how can decision-makers harness the Metaverse for their...
The Metaverse and AI: how can decision-makers harness the Metaverse for their...The Metaverse and AI: how can decision-makers harness the Metaverse for their...
The Metaverse and AI: how can decision-makers harness the Metaverse for their...
Jen Stirrup
 
Pushing the limits of ePRTC: 100ns holdover for 100 days
Pushing the limits of ePRTC: 100ns holdover for 100 daysPushing the limits of ePRTC: 100ns holdover for 100 days
Pushing the limits of ePRTC: 100ns holdover for 100 days
Adtran
 
Climate Impact of Software Testing at Nordic Testing Days
Climate Impact of Software Testing at Nordic Testing DaysClimate Impact of Software Testing at Nordic Testing Days
Climate Impact of Software Testing at Nordic Testing Days
Kari Kakkonen
 
Essentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FMEEssentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FME
Safe Software
 
Free Complete Python - A step towards Data Science
Free Complete Python - A step towards Data ScienceFree Complete Python - A step towards Data Science
Free Complete Python - A step towards Data Science
RinaMondal9
 

Recently uploaded (20)

LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
 
Removing Uninteresting Bytes in Software Fuzzing
Removing Uninteresting Bytes in Software FuzzingRemoving Uninteresting Bytes in Software Fuzzing
Removing Uninteresting Bytes in Software Fuzzing
 
Le nuove frontiere dell'AI nell'RPA con UiPath Autopilot™
Le nuove frontiere dell'AI nell'RPA con UiPath Autopilot™Le nuove frontiere dell'AI nell'RPA con UiPath Autopilot™
Le nuove frontiere dell'AI nell'RPA con UiPath Autopilot™
 
Introduction to CHERI technology - Cybersecurity
Introduction to CHERI technology - CybersecurityIntroduction to CHERI technology - Cybersecurity
Introduction to CHERI technology - Cybersecurity
 
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
 
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
 
zkStudyClub - Reef: Fast Succinct Non-Interactive Zero-Knowledge Regex Proofs
zkStudyClub - Reef: Fast Succinct Non-Interactive Zero-Knowledge Regex ProofszkStudyClub - Reef: Fast Succinct Non-Interactive Zero-Knowledge Regex Proofs
zkStudyClub - Reef: Fast Succinct Non-Interactive Zero-Knowledge Regex Proofs
 
Assure Contact Center Experiences for Your Customers With ThousandEyes
Assure Contact Center Experiences for Your Customers With ThousandEyesAssure Contact Center Experiences for Your Customers With ThousandEyes
Assure Contact Center Experiences for Your Customers With ThousandEyes
 
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...
 
Monitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR EventsMonitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR Events
 
Elizabeth Buie - Older adults: Are we really designing for our future selves?
Elizabeth Buie - Older adults: Are we really designing for our future selves?Elizabeth Buie - Older adults: Are we really designing for our future selves?
Elizabeth Buie - Older adults: Are we really designing for our future selves?
 
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
 
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
 
PCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase TeamPCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase Team
 
Epistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI supportEpistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI support
 
The Metaverse and AI: how can decision-makers harness the Metaverse for their...
The Metaverse and AI: how can decision-makers harness the Metaverse for their...The Metaverse and AI: how can decision-makers harness the Metaverse for their...
The Metaverse and AI: how can decision-makers harness the Metaverse for their...
 
Pushing the limits of ePRTC: 100ns holdover for 100 days
Pushing the limits of ePRTC: 100ns holdover for 100 daysPushing the limits of ePRTC: 100ns holdover for 100 days
Pushing the limits of ePRTC: 100ns holdover for 100 days
 
Climate Impact of Software Testing at Nordic Testing Days
Climate Impact of Software Testing at Nordic Testing DaysClimate Impact of Software Testing at Nordic Testing Days
Climate Impact of Software Testing at Nordic Testing Days
 
Essentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FMEEssentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FME
 
Free Complete Python - A step towards Data Science
Free Complete Python - A step towards Data ScienceFree Complete Python - A step towards Data Science
Free Complete Python - A step towards Data Science
 

Streaming and Visualizing Data with D3.js

  • 1. IN THIS TUTORIAL, WE SHOWCASE WHAT MORE CAN BE DONE WITH D3.js and PUBNUB! +
  • 2. WHAT IS D3.JS? • A JavaScript Library • Lets you stream data to create interactive graphs & charts that run in the browser • A very powerful tool for creating eye- catching data visualizations
  • 3. TODAY…WE SHOWCASE WHAT YOU CAN DO MORE WITH D3 & PUBNUB. LET’S BEGIN AND GET MORE VISUAL WITH A BUBBLE CHART!
  • 4. PREREQUISITES • Basic to intermediate knowledge of JavaScript Document Object Model (DOM) • Basic understanding of SVG and D3.js
  • 5. STEPS WE’LL TAKE In this tutorial, you will learn how to: 1. Create a static bubble chart using D3.js 2. Bind streaming JSON data to the chart 3. Live-update and animate the bubble chart
  • 6. STEP #1 CREATE A STATIC BUBBLE CHART TO GET STARTED… Include d3.min.js in your HTML file, then define a layout.
  • 7. STEP 1: CREATE A STATIC BUBBLE CHART 1.1. Use D3.js’s Graphical Layout To draw a bubble chart, we create a pack layout using d3.layout.pack() object.
  • 8. STEP 1: CREATE A STATIC BUBBLE CHART 1.2. WORK WITH JSON DATA 1. Sign up for a PubNub account. 2. Get your unique PubNub keys in the PubNub Developer Portal. 3. Clone the GitHub repository, and enter your unique PubNub keys on the PubNub initialization. For now, we’ll use simulated data, which is similar to the actual streaming JSON we will use in this tutorial. Assume the data came from our global data centers, and each data set represents a country, and access volume from the country.
  • 9. STEP 1: CREATE A STATIC BUBBLE CHART 1.2. WORK WITH JSON DATA 4. Customize this raw data to be used in the pack layout. The pack layout is part of D3′s family of hierarchical layouts and by default, D3 assumes that the input data is an object with a children array, so it is convenient to return the object looks like, {children: [an array of objects]}
  • 10. STEP 1: CREATE A STATIC BUBBLE CHART 1.2. WORK WITH JSON DATA 5. The className values are to be used to colorize each SVG circle by country, defined in CSS.
  • 11. STEP 1: CREATE A STATIC BUBBLE CHART 1.3. ENTER DATA INTO THE LAYOUT 1. We are loading the tailored data into layout object’s nodes() function, which automagically populates graphical data (size of each circle and positions) with a set of standard attributes, so all the circles will nicely fit in a chart. 2. Then, use the generated layout calculations to display in SVG.
  • 12. AWESOME! YOU’VE CREATED A BUBBLE CHART! JUST A FEW MORE STEPS…
  • 13. STEP #2 MAKE D3.JS DYNAMIC WITH STREAMING JSON WE ARE READY TO REPLACE THE STATIC JSON WITH LIVE JSON FROM PUBNUB DATA STREAMS
  • 14. STEP 2: MAKE D3.js DYNAMIC WITH STREAMING JSON • Include the PubNub JavaScript libraries in your HTML to begin (You’ll first need to sign up for a PubNub account. Once you sign up, you can get your unique PubNub keys in the PubNub Developer Portal). • We are using a chunk of predefined set of data here for the exercise, so let’s initialize the API with the existing channel.
  • 15. STEP 2: MAKE D3.js DYNAMIC WITH STREAMING JSON 2.1. SUBSCRIBE THE LIVE DATA 1. To retrieve the live data, you simply use PubNub subscribe() API. 2. Once you successfully retrieve the data from the stream, call the callback function to draw the chart.
  • 16. NOW, EVERY TIME A NEW SET OF DATA COMES, NEW BUBBLES ARE DISPLAYED! HOWEVER, THEY KEEP BEING ADDED ON TOP OF THE PREVIOUS CHART. THIS LOOKS PRETTY FUNKY, BUT IT IS NOT WHAT WE WANT! WE NEED TO FIX THIS.
  • 17. STEP #3 LIVE-UPDATE & ANIMATE THE BUBBLES! OK, let’s bind data to elements correctly!
  • 18. STEP 3: LIVE-UPDATE & ANIMATE THE BUBBLES! 3.1. ASSIGN EACH NODE WITH A UNIQUE NAME D3 uses the enter, update, and exit pattern to join data to DOM. At the previous step 1.3, you have enter() the initial data. To make the node updateable, you need to assign a name to each node. D3 takes a key function as a second argument to the data() method. Modify the code to assign a unique field name:
  • 19. STEP 3: LIVE-UPDATE & ANIMATE THE BUBBLES! 3.2. CREATE CHAINED TRANSISTIONS • Also, at the step 1.3, we celled data(), enter() and append() sequentially. • To enter new data to the existing nodes, we are going to update them. This way, each assigned bubble circle updates its size and position correctly, instead of creating a new one with new data.
  • 20. STEP 3: LIVE-UPDATE & ANIMATE THE BUBBLES! 3.2. CREATE CHAINED TRANSISTIONS To make smooth transitions between old and new data, apply a transition only to the updating nodes, and not entering nodes. The trick is to create the transition on the updating elements before the entering elements because enter().append() merges entering elements into the update selection. 1 2 3
  • 21. STEP 3: LIVE-UPDATE & ANIMATE THE BUBBLES! 3.2. CREATE CHAINED TRANSISTIONS Note: Some bubbles may be a null in upcoming data set, and need to be removed. We use exit() and remove(). Also giving an opacity (1 to 0) transition to create a complete sequence of chained transitions.
  • 22. STEP 3: LIVE-UPDATE & ANIMATE THE BUBBLES! 3.2. CREATE CHAINED TRANSISTIONS In this example, we are transitioning the position and radius of each bubble upon updating the data, also opacity upon entering and exiting. Moreover, with using delay method along with transition, we are making the animation effect more interesting. Tweak the values and see what works the best.
  • 23. Fun with D3js: Data Visualization Eye Candy with Streaming JSON More PubNub Visualization Tutorials www.PubNub.com FOR MORE INFO