D3.js Tutorial (Hands on Session)

Slides:



Advertisements
Similar presentations
Samsung Smart TV is a web-based application running on an application engine installed on digital TVs connected to the Internet.
Advertisements

1/7 ITApplications XML Module Session 8: Introduction to Programming with XML.
CSCI 3100 Tutorial 6 Web Development Tools 1 Cuiyun GAO 1.
Chapter 16 Dynamic HTML and Animation The Web Warrior Guide to Web Design Technologies.
 2008 Pearson Education, Inc. All rights reserved Document Object Model (DOM): Objects and Collections.
Philly.NET Hands-On jQuery + Plug-ins Bill Wolff, Rob Keiser.
1 Using jQuery JavaScript & jQuery the missing manual (Second Edition)
CST JavaScript Validating Form Data with JavaScript.
DHTML. What is DHTML?  DHTML is the combination of several built-in browser features in fourth generation browsers that enable a web page to be more.
Bringing pages to life with jQuery BEAR BIBEAULT YEHUDA KATZ.
UNIT 8 DRAWING WITH THE HTML5 CANVAS ELEMENTS AND FORMS.
HTML DOM.  The HTML DOM defines a standard way for accessing and manipulating HTML documents.  The DOM presents an HTML document as a tree- structure.
HTML Boot Camp: Rules and Images
Lecture 11 – DOM Scripting SFDV3011 – Advanced Web Development Reference: 1.
Images (1) Three most popular formats – Graphics Interchange Format (GIF) – Joint Photographic Experts Group (JPEG) – Portable Network Graphics (PNG) –
Interacting with a Web Page using JavaScript Mat Kelly GTAI Presentation January 10, 2014.
JavaScript, Fourth Edition
INTRODUCTION TO JAVASCRIPT AND DOM Internet Engineering Spring 2012.
INTRODUCTION TO HTML5 Using jQuery with HTML5. Introducing jQuery  Although it is not a part of any W3C or WHATWG specification, jQuery performs an important.
Javascript II DOM & JSON. In an effort to create increasingly interactive experiences on the web, programmers wanted access to the functionality of browsers.
 2004 Prentice Hall, Inc. All rights reserved. Chapter 13 - Dynamic HTML: Object Model and Collections Outline 13.1 Introduction 13.2 Object Referencing.
SVG for Designers Tom Hoferek. Objectives Introduce SVG Illustrate its capabilities Demonstrate SVG in action Speculate, discuss, answer questions.
Introduction to Programming the WWW I CMSC Winter 2003 Lecture 10.
Internet & World Wide Web How to Program, 5/e. © by Pearson Education, Inc. All Rights Reserved.
JQuery Introduction © Copyright 2014, Fred McClurg All Rights Reserved.
Internet & World Wide Web How to Program, 5/e. © by Pearson Education, Inc. All Rights Reserved.2 Revised by Dr. T. Tran for CSI3140.
 2008 Pearson Education, Inc. All rights reserved Document Object Model (DOM): Objects and Collections.
Review of the DOM Node properties and methods Some ways of accessing nodes Appending, copying and removing nodes Event handling – Inline – Scripting –
LAB 03: VISUALIZATION WITH D3 September 30, 2015 SDS 235 Visual Analytics.
Data Visualization Fall What D3 is? Fall 2015Data Visualization2 JavaScript library for manipulating documents based on data Data-Driven Documents.
D3 Practicum CS 4460 – Information Visualization Megha Sandesh Prepared under advisement by Dr.Fames Foley.
Document Object Model Nasrullah. DOM When a page is loaded,browser creates a Document Object Model of the Page.
Introduction to JQuery COGS 187A – Fall JQuery jQuery is a JavaScript library, and allows us to manipulate HTML and CSS after the page has been.
Chapter 6 Murach's JavaScript and jQuery, C6© 2012, Mike Murach & Associates, Inc.Slide 1.
HTML Tutorial. What is HTML HTML is a markup language for describing web documents (web pages) HTML documents are described by HTML tags Each HTML tag.
Internet & World Wide Web How to Program, 5/e.  JavaScript events  allow scripts to respond to user interactions and modify the page accordingly  Events.
1 Using jQuery JavaScript & jQuery the missing manual (Second Edition)
HTML 5 (Part 1) – Start from SCRATCH. HTML 5 – Start from SCRATCH.
Part – 3 : HTML 5 SVG Tag. † SVG stands for Scalable Vector Graphics. † SVG is used to define vector-based graphics for the Web. † SVG defines the graphics.
XHTML. What Is XHTML? XHTML stands for EXtensible HyperText Markup Language XHTML is almost identical to HTML XHTML is stricter than HTML XHTML is HTML.
THE DOM.
Section 10.1 Define scripting
Introduction to.
DHTML.
Project 1 Introduction to HTML.
What is a Function Expression?
SVG & DOM Manipulation via Javascript
Lab 03: Visualization with d3
Applied Component I Unit II Introduction of java-script
Using DHTML to Enhance Web Pages
CIIT-Human Computer Interaction-CSC456-Fall-2015-Mr
Inserting and Working with Images
AJAX.
Revision.
Prepared for Md. Zakir Hossain Lecturer, CSE, DUET Prepared by Miton Chandra Datta
Introduction to D3.js and Bar Chart in D3.js
Skills learned in Lab 1 Web GUI framework HTML tags and attributes
HTML A brief introduction HTML.
jQuery The Easy JavaScript Nikolay Chochev Technical Trainer
Tutorial 6 Creating Dynamic Pages
Introduction to Programming the WWW I
D3.js Tutorial (Hands on Session)
Javascript and JQuery SRM DSC.
Tutorial 7 – Integrating Access With the Web and With Other Programs
Week 10 - HTML SVG Student: Vladislovas Karalius
HTML5 - 2 Forms, Frames, Graphics.
Class 4: Building Interactive Web Pages
Web Client Side Technologies Raneem Qaddoura
Lab 1: D3 Setup John Fallon
Web Programming and Design
Presentation transcript:

D3.js Tutorial (Hands on Session) Ayush Kumar and Klaus Mueller

D3: Data-Driven Documents AAPL AMZN IBM MSFT Lines --- horizons ---- areas ---- stacked areas ---- streamgraph ---- overlapping areas ----- grouped bars ---- stacked bars ----- bars ----- donut https://bl.ocks.org/mbostock/1256572

D3: Data-Driven Documents D3.js is a JavaScript library for manipulating documents based on data Data Driven Transformation Lines --- horizons ---- areas ---- stacked areas ---- streamgraph ---- overlapping areas ----- grouped bars ---- stacked bars ----- bars ----- donut

D3: Technology & Concept SVG – Scalable Vector Graphics Transitions Data Scaling Data Binding Data Display & Charting D3 Library JQuery (Bonus) Data Visualization JSON/CSV Array & Objects Lines --- horizons ---- areas ---- stacked areas ---- streamgraph ---- overlapping areas ----- grouped bars ---- stacked bars ----- bars ----- donut

Replace “CSE564” with your “Project_Folder” name Directory Structure Replace “CSE564” with your “Project_Folder” name CSE564/ index.html CSE564 /lib/ d3.v4.js CSE564 /js/ test.js CSE564 /css/ style.css CSE564 /data/ iris.csv http://www3.cs.stonybrook.edu/~aykumar/CSE564.zip

Please do not be hesitant to ask questions! VERY VERY IMPORTANT !!! Please do not be hesitant to ask questions!

SVG Basics (0,0) y SVG is an XML language, similar to XHTML, which can be used to draw vector graphics. It can be used to create an image either by specifying all the lines and shapes necessary, by modifying already existing raster images, or by a combination of both. Lines --- horizons ---- areas ---- stacked areas ---- streamgraph ---- overlapping areas ----- grouped bars ---- stacked bars ----- bars ----- donut x

https://developer.mozilla.org/en-US/docs/Web/SVG/Tutorial/Basic_Shapes SVG Shapes <rect> <svg width="400" height="110">   <rect width="300" height="100" style="fill:rgb(0,0,255);stroke-width:3;stroke:rgb(0,0,0)" /> </svg> <circle> <svg height="100" width="100">   <circle cx="50" cy="50" r="40" stroke="black" stroke-width="3" fill="red" /> </svg> <ellipse> <svg height="140" width="500">   <ellipse cx="200" cy="80" rx="100" ry="50"  style="fill:yellow;stroke:purple;stroke-width:2" /> </svg> <line> <svg height="210" width="500">   <line x1="0" y1="0" x2="200" y2="200" style="stroke:rgb(255,0,0);stroke-width:2" /> </svg> <text> <svg height="30" width="200">   <text x="0" y="15" fill="red">I love SVG!</text> </svg> <path> <svg height=“500" width=“500"> <path d="M350 120 L300 300 L425 300 Z" style="fill:green;stroke:steelblue;stroke-width:2" /> </svg> <svg width="200" height="200" viewBox="0 0 100 100"> he whole SVG canvas here is 200px by 200px in size. However, the viewBoxattribute defines the portion of that canvas to display. These 200x200 pixels display an area that starts at user unit (0,0) and spans 100x100 user units to the right and to the bottom. https://developer.mozilla.org/en-US/docs/Web/SVG/Tutorial/Basic_Shapes

How to make this Work ??? AND NOW D3 … DOM SELECTION & MANIPULATION LOADING DATA ENTER-UPDATE-EXIT PARADIGM (DATA BINDING) CHARTS SCALES AXES TRANSITIONS AND INTERACTION How to make this Work ???

Setup D3.js Development Environment D3 Begins… Setup D3.js Development Environment D3 library Web server Editor Web browser

D3 Begins… Setup D3.js Development Environment D3 library Web server Editor Web browser <script src="../d3.js"></script>  This defines a global JavaScript object d3, which includes all the important methods to start with, just like jQuery includes a global object called jQuery (or $). <script src="../d3.min.js"></script> <script src="https://d3js.org/d3.v4.min.js"></script>

D3 Begins… python -m SimpleHTTPServer 8000 http://localhost:8000/ Setup D3.js Development Environment D3 library Web server Editor Web browser python -m SimpleHTTPServer 8000 http://localhost:8000/

Setup D3.js Development Environment D3 Begins… Setup D3.js Development Environment D3 library Web server Editor Web browser Ctrl+Alt+Q (Stop the Server) Ctrl+Alt+L (Start the Server) and direct the page to index.html WebStorm

Editor Set Up Open Editor and Navigate to Settings Ctrl+Alt+Q (Stop the Server) Ctrl+Alt+L (Start the Server) and direct the page to index.html WebStorm Download & Install Atom

Editor Set Up Done with Installation, Now Use below Keys in Editor to Launch the Server Search for atom-live-server 2 ctrl-alt-l launch live server on port 3000. ctrl-alt-q stop live server. ctrl-alt-3 launch live server on port 3000. ctrl-alt-4 launch live server on port 4000. ctrl-alt-5 launch live server on port 5000. ctrl-alt-8 launch live server on port 8000. ctrl-alt-9 launch live server on port 9000. 4 Open Setting Click Install Ctrl+Alt+Q (Stop the Server) Ctrl+Alt+L (Start the Server) and direct the page to index.html 1 3 Navigate to Install Option Download Atom

Setup D3.js Development Environment D3 Begins… Setup D3.js Development Environment D3 library Web server Editor Web browser Ctrl+Alt+Q (Stop the Server) Ctrl+Alt+L (Start the Server) and direct the page to index.html

D3 DOM DOM SELECTION & MANIPULATION LOADING DATA ENTER-UPDATE-EXIT PARADIGM (DATA BINDING) CHARTS SCALES AXES TRANSITIONS AND INTERACTION The Document Object Model (DOM) is a cross-platform and language-independent application programming interface that treats an HTML, XHTML, or XML document as a tree structure where in each node is an object representing a part of the document https://www.cs.pu.edu.tw/~tsay/course/webprog/notes/DOM

DOM Selection d3.select() d3.selectAll() Select Element By Tag Name Select Element By Id d3.selectAll() Select Element By CSS Class Name The following example demonstrates selecting the first matching element by tag name using d3.select. d3.select("p") returns first <p> element and then, .style("color","green") d3.select() method can also be used to get an element with specified id

DOM Manipulation text() append() insert() remove() html() attr() property() style() Use d3.selection.append() method to create a new DOM element and add it at the end of selected DOM element.  d3.select("body") returns the body element and .append("p") creates a new <p> element and adds it just before the end of the <body>.  I think the reason for choosing insert() over append() is rather a matter of handling mouse events. Insert is associated at index where to put the selected element. d3.select("p") selects the <p> element and .attr("class","error") applies class attribute to the paragraph element.

D3 Data Loading DOM SELECTION & MANIPULATION LOADING DATA ENTER-UPDATE-EXIT PARADIGM (DATA BINDING) CHARTS SCALES AXES TRANSITIONS AND INTERACTION

D3 Data Loading d3.csv() d3.json() d3.tsv() d3.xml()

D3 DOM DOM SELECTION & MANIPULATION LOADING DATA ENTER-UPDATE-EXIT PARADIGM (DATA BINDING) CHARTS SCALES AXES TRANSITIONS AND INTERACTION The Document Object Model (DOM) is a cross-platform and language-independent application programming interface that treats an HTML, XHTML, or XML document as a tree structure where in each node is an object representing a part of the document

D3 Data Binding data() enter() exit() datum() The data() function is used to join the specified array of data to the selected DOM elements and return the updated selection demonstrates how to join data as an array into your existing DOM element using data() function. Remember, you need to pass an array to the data() function. It a constant value. .text(function(d, i) { return d; }); this text function adds the data as tdoes not do anything if you provide ext to each of our selection element. Each array value is passed as the first argument (d) to text function. In this case, an existing text from paragraph element, 'D3 tutorial', will get replaced with the first array value 'Hello World'.

D3 Data Binding data() enter() exit() datum() The enter() method dynamically creates placeholder references corresponding to the number of data values. The output of enter() can be fed to append() method and append() will create DOM elements for which there are no corresponding DOM elements on the page. At this point, there are no span elements in the body. So this will return an empty array. The enter() function checks for <span> elements corresponding to our five array elements. Since it does not find any, it will create a span for each of the five elements. By applying the data() operator to our selection, we join data items and DOM elements with each other:

D3 CHARTS DOM SELECTION & MANIPULATION LOADING DATA ENTER-UPDATE-EXIT PARADIGM (DATA BINDING) CHARTS SCALES AXES TRANSITIONS AND INTERACTION

D3 SCALING DOM SELECTION & MANIPULATION LOADING DATA ENTER-UPDATE-EXIT PARADIGM (DATA BINDING) CHARTS SCALES AXES TRANSITIONS AND INTERACTION

D3 SCALING

D3 Axis DOM SELECTION & MANIPULATION LOADING DATA ENTER-UPDATE-EXIT PARADIGM (DATA BINDING) CHARTS SCALES AXES TRANSITIONS AND INTERACTION

D3 Axis (Exactly Same Data)

D3 Animation DOM SELECTION & MANIPULATION LOADING DATA ENTER-UPDATE-EXIT PARADIGM (DATA BINDING) CHARTS SCALES AXES TRANSITIONS AND INTERACTION

D3 Animation

D3 Animation

Bl.ock Builder https://blockbuilder.org/

References https://www.dashingd3js.com/d3-v4-tutorial https://github.com/d3/d3/wiki/Gallery http://poloclub.gatech.edu/cse6242/2014spring/lectures/CSE6242-20140123-Stolper-D3.pdf https://bost.ocks.org/mike/d3/workshop/#0 http://www.tutorialsteacher.com/d3js https://square.github.io/intro-to-d3/ http://alignedleft.com/tutorials https://www.tutorialspoint.com/d3js/