SlideShare une entreprise Scribd logo
1  sur  23
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

Contenu connexe

Tendances

Blazing Performance with Flame Graphs
Blazing Performance with Flame GraphsBlazing Performance with Flame Graphs
Blazing Performance with Flame GraphsBrendan Gregg
 
Kubernetesのしくみ やさしく学ぶ 内部構造とアーキテクチャー
Kubernetesのしくみ やさしく学ぶ 内部構造とアーキテクチャーKubernetesのしくみ やさしく学ぶ 内部構造とアーキテクチャー
Kubernetesのしくみ やさしく学ぶ 内部構造とアーキテクチャーToru Makabe
 
C#でわかる こわくないMonad
C#でわかる こわくないMonadC#でわかる こわくないMonad
C#でわかる こわくないMonadKouji Matsui
 
How To Become Better Engineer
How To Become Better EngineerHow To Become Better Engineer
How To Become Better EngineerDaeMyung Kang
 
イベント駆動プログラミングとI/O多重化
イベント駆動プログラミングとI/O多重化イベント駆動プログラミングとI/O多重化
イベント駆動プログラミングとI/O多重化Gosuke Miyashita
 
Twitterのsnowflakeについて
TwitterのsnowflakeについてTwitterのsnowflakeについて
Twitterのsnowflakeについてmoai kids
 
SQLアンチパターン(インデックスショットガン)
SQLアンチパターン(インデックスショットガン)SQLアンチパターン(インデックスショットガン)
SQLアンチパターン(インデックスショットガン)Tomoaki Uchida
 
イルカさんチームからゾウさんチームに教えたいMySQLレプリケーション
イルカさんチームからゾウさんチームに教えたいMySQLレプリケーションイルカさんチームからゾウさんチームに教えたいMySQLレプリケーション
イルカさんチームからゾウさんチームに教えたいMySQLレプリケーションyoku0825
 
今からでも遅くないDBマイグレーション - Flyway と SchemaSpy の紹介 -
今からでも遅くないDBマイグレーション - Flyway と SchemaSpy の紹介 -今からでも遅くないDBマイグレーション - Flyway と SchemaSpy の紹介 -
今からでも遅くないDBマイグレーション - Flyway と SchemaSpy の紹介 -onozaty
 
5分で分かるgitのrefspec
5分で分かるgitのrefspec5分で分かるgitのrefspec
5分で分かるgitのrefspecikdysfm
 
SQLアンチパターン - 開発者を待ち受ける25の落とし穴 (拡大版)
SQLアンチパターン - 開発者を待ち受ける25の落とし穴 (拡大版)SQLアンチパターン - 開発者を待ち受ける25の落とし穴 (拡大版)
SQLアンチパターン - 開発者を待ち受ける25の落とし穴 (拡大版)Takuto Wada
 
それはYAGNIか? それとも思考停止か?
それはYAGNIか? それとも思考停止か?それはYAGNIか? それとも思考停止か?
それはYAGNIか? それとも思考停止か?Yoshitaka Kawashima
 
本格的に始めるzsh
本格的に始めるzsh本格的に始めるzsh
本格的に始めるzshHideaki Miyake
 
Serf / Consul 入門 ~仕事を楽しくしよう~
Serf / Consul 入門 ~仕事を楽しくしよう~Serf / Consul 入門 ~仕事を楽しくしよう~
Serf / Consul 入門 ~仕事を楽しくしよう~Masahito Zembutsu
 
Cgroupあれこれ-第4回コンテナ型仮想化の情報交換会資料
Cgroupあれこれ-第4回コンテナ型仮想化の情報交換会資料Cgroupあれこれ-第4回コンテナ型仮想化の情報交換会資料
Cgroupあれこれ-第4回コンテナ型仮想化の情報交換会資料KamezawaHiroyuki
 
カーネル空間ですべてのプロセスを動かすには -TAL, SFI, Wasmとか - カーネル/VM探検隊15
カーネル空間ですべてのプロセスを動かすには -TAL, SFI, Wasmとか - カーネル/VM探検隊15カーネル空間ですべてのプロセスを動かすには -TAL, SFI, Wasmとか - カーネル/VM探検隊15
カーネル空間ですべてのプロセスを動かすには -TAL, SFI, Wasmとか - カーネル/VM探検隊15Takaya Saeki
 
雑なMySQLパフォーマンスチューニング
雑なMySQLパフォーマンスチューニング雑なMySQLパフォーマンスチューニング
雑なMySQLパフォーマンスチューニングyoku0825
 

Tendances (20)

Blazing Performance with Flame Graphs
Blazing Performance with Flame GraphsBlazing Performance with Flame Graphs
Blazing Performance with Flame Graphs
 
Kubernetesのしくみ やさしく学ぶ 内部構造とアーキテクチャー
Kubernetesのしくみ やさしく学ぶ 内部構造とアーキテクチャーKubernetesのしくみ やさしく学ぶ 内部構造とアーキテクチャー
Kubernetesのしくみ やさしく学ぶ 内部構造とアーキテクチャー
 
C#でわかる こわくないMonad
C#でわかる こわくないMonadC#でわかる こわくないMonad
C#でわかる こわくないMonad
 
How To Become Better Engineer
How To Become Better EngineerHow To Become Better Engineer
How To Become Better Engineer
 
イベント駆動プログラミングとI/O多重化
イベント駆動プログラミングとI/O多重化イベント駆動プログラミングとI/O多重化
イベント駆動プログラミングとI/O多重化
 
Twitterのsnowflakeについて
TwitterのsnowflakeについてTwitterのsnowflakeについて
Twitterのsnowflakeについて
 
Linux Namespace
Linux NamespaceLinux Namespace
Linux Namespace
 
SQLアンチパターン(インデックスショットガン)
SQLアンチパターン(インデックスショットガン)SQLアンチパターン(インデックスショットガン)
SQLアンチパターン(インデックスショットガン)
 
イルカさんチームからゾウさんチームに教えたいMySQLレプリケーション
イルカさんチームからゾウさんチームに教えたいMySQLレプリケーションイルカさんチームからゾウさんチームに教えたいMySQLレプリケーション
イルカさんチームからゾウさんチームに教えたいMySQLレプリケーション
 
PostgreSQLセキュリティ総復習
PostgreSQLセキュリティ総復習PostgreSQLセキュリティ総復習
PostgreSQLセキュリティ総復習
 
今からでも遅くないDBマイグレーション - Flyway と SchemaSpy の紹介 -
今からでも遅くないDBマイグレーション - Flyway と SchemaSpy の紹介 -今からでも遅くないDBマイグレーション - Flyway と SchemaSpy の紹介 -
今からでも遅くないDBマイグレーション - Flyway と SchemaSpy の紹介 -
 
5分で分かるgitのrefspec
5分で分かるgitのrefspec5分で分かるgitのrefspec
5分で分かるgitのrefspec
 
SQLアンチパターン - 開発者を待ち受ける25の落とし穴 (拡大版)
SQLアンチパターン - 開発者を待ち受ける25の落とし穴 (拡大版)SQLアンチパターン - 開発者を待ち受ける25の落とし穴 (拡大版)
SQLアンチパターン - 開発者を待ち受ける25の落とし穴 (拡大版)
 
それはYAGNIか? それとも思考停止か?
それはYAGNIか? それとも思考停止か?それはYAGNIか? それとも思考停止か?
それはYAGNIか? それとも思考停止か?
 
本格的に始めるzsh
本格的に始めるzsh本格的に始めるzsh
本格的に始めるzsh
 
Serf / Consul 入門 ~仕事を楽しくしよう~
Serf / Consul 入門 ~仕事を楽しくしよう~Serf / Consul 入門 ~仕事を楽しくしよう~
Serf / Consul 入門 ~仕事を楽しくしよう~
 
Consistent hash
Consistent hashConsistent hash
Consistent hash
 
Cgroupあれこれ-第4回コンテナ型仮想化の情報交換会資料
Cgroupあれこれ-第4回コンテナ型仮想化の情報交換会資料Cgroupあれこれ-第4回コンテナ型仮想化の情報交換会資料
Cgroupあれこれ-第4回コンテナ型仮想化の情報交換会資料
 
カーネル空間ですべてのプロセスを動かすには -TAL, SFI, Wasmとか - カーネル/VM探検隊15
カーネル空間ですべてのプロセスを動かすには -TAL, SFI, Wasmとか - カーネル/VM探検隊15カーネル空間ですべてのプロセスを動かすには -TAL, SFI, Wasmとか - カーネル/VM探検隊15
カーネル空間ですべてのプロセスを動かすには -TAL, SFI, Wasmとか - カーネル/VM探検隊15
 
雑なMySQLパフォーマンスチューニング
雑なMySQLパフォーマンスチューニング雑なMySQLパフォーマンスチューニング
雑なMySQLパフォーマンスチューニング
 

En vedette

HiTech Manufacturing Use Cases/Examples
HiTech Manufacturing Use Cases/ExamplesHiTech Manufacturing Use Cases/Examples
HiTech Manufacturing Use Cases/ExamplesTIBCO 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 ThingsBhavana Srinivas
 
flowspec @ APF 2013
flowspec @ APF 2013flowspec @ APF 2013
flowspec @ APF 2013Tom Paseka
 
OpenLayers vs. Leaflet
OpenLayers vs. LeafletOpenLayers vs. Leaflet
OpenLayers vs. Leafletdasjo
 
Websocket + Redis pubsub
Websocket + Redis pubsubWebsocket + Redis pubsub
Websocket + Redis pubsubKai 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.ioArnout Kazemier
 
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 InsightsTIBCO 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.ioMindfire 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 BusinessRedis Labs
 
Going realtime with Socket.IO
Going realtime with Socket.IOGoing realtime with Socket.IO
Going realtime with Socket.IOChristian 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 RedisConfRedis 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, DataDogRedis 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 RedisYork 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, InuitRedis 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 Rediscacois
 

En vedette (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
 

Similaire à 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 JSONTomomi Imura
 
D3 Mapping Visualization
D3 Mapping VisualizationD3 Mapping Visualization
D3 Mapping VisualizationSudhir 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 GenerationTJ Torres
 
Plan601 e session 2 demo
Plan601 e session 2 demoPlan601 e session 2 demo
Plan601 e session 2 demorkottam
 
Plan601 e session 2 demo
Plan601 e session 2 demoPlan601 e session 2 demo
Plan601 e session 2 demorkottam
 
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 demorkottam
 
Plan601 e session 2 demo
Plan601 e session 2 demoPlan601 e session 2 demo
Plan601 e session 2 demorkottam
 
Big data analytics project report
Big data analytics project reportBig data analytics project report
Big data analytics project reportManav Deshmukh
 
Plan601 e session 2 demo
Plan601 e session 2 demoPlan601 e session 2 demo
Plan601 e session 2 demorkottam
 
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 minutesJos Dirksen
 
Using QLIK with AWS & Python
Using QLIK with AWS & PythonUsing QLIK with AWS & Python
Using QLIK with AWS & PythonBruce 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.docxtodd331
 
plan601 e session 2 demo
plan601 e session 2 demoplan601 e session 2 demo
plan601 e session 2 demorkottam
 

Similaire à 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
 

Plus de PubNub

Defining the IoT Stack
Defining the IoT StackDefining the IoT Stack
Defining the IoT StackPubNub
 
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 DestroyerPubNub
 
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 PubNubPubNub
 

Plus de 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
 

Dernier

Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slidevu2urc
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?Igalia
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Enterprise Knowledge
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?Antenna Manufacturer Coco
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Scriptwesley chun
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CVKhem
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processorsdebabhi2
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherRemote DBA Services
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...DianaGray10
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobeapidays
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 

Dernier (20)

Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 

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