
Discover how to build data driven web interfaces with D3.js and Firebase, creating SVG visualizations—bar charts, pie charts, line graphs—with scales, axes, and transitions, connected to Firestore in real time.
In this video we'll look at some examples of data visualizations on the web, which have been made using the D3.js library.
Here I'll show you which code editor I'll be using for the course (VS code) as well as some of the packages I'll be using for VS Code too.
Here I'll show you how to access all of the course files from the course repository on GitHub.
If you need extra help with some JavaScript topics (or HTML, CSS & Firebase), I'll show you where to get access to additional free tutorials.
We'll take a look at what SVG's actually are and why we use them.
Here we'll create some simple SVG shapes directly in the HTML code.
Now we'll take a look at a more complex SVG element - paths, Paths are used to create more complex SVG shapes.
We'll get the D3.js library from the GitHub repo and load it into our HTML file.
This course is taught using D3 v5. If you use the newly released v6, please check out the latest section D3 v6 when you encounter errors when following along the lecture. If it doesn't solve your problem, please use the Q&A feature to ask your question.
Learn to select DOM elements with D3.js using select and select all, and compare with query selector. Set up a canvas in the page to inject SVGs via D3.
Select the canvas with d3, append an svg container, and append shapes such as a rect, circle, and line; learn to store returned elements for further chaining with attributes.
learn how to apply attributes to d3 elements using the attr method and method chaining, adding width, height, fill, and coordinates to svg, rect, circle, and line elements.
Append a text element to an SVG with d3, set x and y, apply a gray fill, and define the text; then use style to apply Arial for graph labels.
Group elements in SVG using a g container to bundle bars, axes, and labels, then apply transforms such as translate to move the entire chart section in one step.
Explore creating and manipulating SVG elements with D3, including rects, circles, lines, paths, and text, then group and transform them, and prepare to map data to visuals.
Bind a data array to an SVG rectangle with d3's data method, driving width, height, and fill from bound data. Access data object D, index I, and selection N.
Convert D3 code from function to arrow functions for cleaner code, noting this binds differently; use n and i to access element and index.
Join data to multiple elements in d3 by selecting all rectangles and binding each object to its corresponding rect, then apply width, height, and fill attributes.
Learn how to use d3's enter selection to create extra dom elements for data when joining to rectangles. The lecture covers enter selection, virtual elements, and appending rects with attributes.
Learn to fetch external JSON data with d3.json, join it to circle elements, and use enter selections to render data-driven planets with radius, distance, and color in an SVG.
Explore why linear scales are essential in D3 bar charts, mapping data values to bar heights within an SVG using domain and range to keep shapes visible.
Create a bar chart by loading menu.json data with D3.js, binding data to rects, and using a linear y-scale with domain 0–1000 and range 0–500 to map orders to height.
Learn how band scales in d3.js split categories into equal bands, map names to domain and x coordinates, and compute band width with padding to fit the svg width.
Explore using d3 min, max, and extent to determine data domain, compute min and max values from orders, and dynamically rescale visuals when new data such as 1500 appears.
Move the SVG creation into the JavaScript file and wrap rectangles in a graph group with margins. Compute graph width and height and translate group to make room for axes.
Learn to add x and y axes to a bar chart using D3 axis generators, create axis groups, and position them with translate based on graph height and scales.
Explore how to invert y scales in D3.js visualizations by flipping the range, adjusting bar heights with graph height, and setting the correct y positions for rectangles.
Format bar chart axes with configurable tick counts and tick labels using D3's ticks and tickFormat, rotate axis labels with text-anchor end, and style ticks with fill color.
Explore how Firestore stores data as collections and documents, with real-time updates that redraw d3 visualizations when the underlying data changes, using auto-generated document IDs.
Create a Firebase project and enable a Firestore database in test mode, then add a dishes collection with fields name and orders to feed bar chart from the previous chapter.
Set up the Firebase config in your HTML by loading Firebase app and Firestore, initialize Firestore as DB, and enable timestamps in snapshots to connect and query Firestore.
Fetch data from a Firestore dishes collection using the database object, convert documents to data, and bind them to rectangles in a D3.js graph.
Learn to enable real-time updates by listening to Firestore changes and applying the D3 update cycle, including enter and exit selections, to auto-refresh a bar chart.
Explore how D3.js joins data to rectangles using the enter and exit selections to manage virtual and real DOM elements, append new rects, and update their attributes.
Learn the D3 update pattern for real-time visualizations with Firestore data, updating scales, joining data, handling exit, updating existing shapes, and adding new elements.
Learn how to implement an update function in a D3.js and Firebase data visualization, updating scales, joining data, and handling enter, update, and exit selections for dynamic charts.
Simulate live data updates with the D3 interval function by incrementing the first data item’s orders every second, then calling the update function to rebind, update axes, and redraw rectangles.
Showcase the D3 exit selection by removing the last bars from the DOM as the data array shrinks, updating and rejoining data every few seconds.
Learn how to implement real-time Firestore updates with onSnapshot to listen to a dishes collection, process document changes, and feed a data array into a D3 update function for visualizations.
Set up a real-time listener on the dishes collection, process added, modified, and removed changes with a switch, update the data array, and refresh the visualization.
Master smooth data updates in D3 by applying transitions to rectangles, animating height changes, and sliding bars on load, with an introduction to tweens for complex shapes.
Explore enter transitions by animating bar height and y position from the graph bottom to final values, with a duration of 500 milliseconds.
Animate updates in d3.js and Firebase by transitioning current bars from their existing y coordinates and heights to new values, with a 500ms duration for smooth data visual updates.
Learn to refactor D3 visualizations by externalizing transitions into a reusable constant and using merge to apply changes to both enter and update selections, reducing duplicated code.
Learn to build custom tweens in D3, using interpolation and a 0-to-1 time ticker to drive width transitions from zero to bandwidth in the enter selection.
Set up a D3.js and Firebase budget visualization project, scaffolding HTML and two JS files, then build the Ninja Wanga pie chart that updates in real time.
Create a styled HTML template using the Materialize CSS library, linking CDN assets, and build a responsive grid with a left form and right canvas for D3 and Firebase projects.
Set up a Firestore collection called expenses, add documents with name and cost fields, import Firebase, initialize Firestore as DB, and enable time stamps in snapshots for future data entry.
Hook up the form to Firestore to add items to the expenses collection, validating name and cost, and converting cost to a number. Clear inputs and reset errors on success.
Generate pie slice angles with the d3 pie generator, then draw the wedges as SVG paths with the arc generator, noting angles are in radians.
Set up the pie chart foundation in D3 by defining dimensions and center, creating an SVG container and group, and configuring a pie generator with a cost-based value accessor.
Create arc paths with the D3 arc generator using start and end angles from a pi generator to render donut slices and bind radii with Firestore for real-time data.
Set up a real-time listener to Firestore's expenses collection to sync doc changes (added, removed, modified) with a data array, then pass updates to Pi and Arc generators for rendering.
Bind real-time updates from Firebase to a pie chart by joining enhanced data to path elements via the enter selection, using a pie generator and arc path to render arcs.
Color the donut wedges with a d3 ordinal scale, using scheme set three for colors. Build the domain from data names via map and apply color(d.data.name) to each slice.
Tackle a project challenge by updating a D3.js donut chart in real time, handling enter, exit, and update selections for Firestore data changes.
Watch the project solution to learn how to rejoin data with D3.js, manage exit selections, and update path elements when data changes, including add, edit, and delete operations.
Explain how to animate arc transitions in a donut chart using a custom d3 arc tween. Interpolate end and start angles to smoothly redraw paths during enter selection.
Learn to create an arc exit tween in d3.js that reverses the enter transition, animating data removal by reversing start and end angles to collapse arcs before removal.
Master smooth data-driven transitions in a pie chart by building a single custom arc tween that updates enter, exit, and update states as data changes in Firestore.
Use the d3 svg legend plugin to render a right-side legend connected to the color scale, with a translated legend group and data-driven updates from Firebase.
Learn to add interactivity to d3 visualizations by enabling hover, click, and tooltips on a pie chart (and bar chart) connected to a Firestore real-time database.
Event listeners let visualizations respond to user events such as click and mouse over. Use D3's on method on a selection to attach a callback that changes a rectangle's color.
Learn to implement mouse over and mouse out events on D3.js path elements, animate transitions to white via an ordinal color scale, and revert colors based on data and index.
Learn how naming transitions in D3 prevents interaction between hover and growth animations, ensuring arcs resize smoothly while mouse over and mouse leave change colors independently.
Attach a click event to each pie slice to delete its Firestore document and refresh the visualization. Read the slice id, reference the expenses collection, and delete the document.
Add interactive tooltips to a D3.js donut chart using the D3-tip plugin, showing name and cost on hover with a delete prompt. Connect the chart to Firebase for real-time updates.
Build the Dojo project with line graphs for daily exercise by category, with hover points, add data for running and swimming, timescales, line paths, and data filtering using d3.
Create an HTML template for a D3 and Firebase project, featuring a grey responsive layout with a top nav, left activity buttons, a right canvas, and a central form.
Implement dom interactivity by wiring button clicks to toggle the active state, update the form activity display, and set the input id and span text for future Firestore storage.
Connect a web form to Firestore, saving input as documents in an activities collection, while initializing Firestore and handling submission validation for future visualizations.
Set up a real-time listener on the Firestore activities collection to stream added, modified, and removed changes into a data array, then update the D3 visualization.
Set up graph margins, define the SVG container and graph group, compute graph width and height, and translate the graph by the margins to prepare for axes.
Set up D3 scales and axes for a time-distance chart, using a time scale on the x axis and a linear scale on the y axis.
Set up domains for x and y scales with d3.extent and d3.max, create bottom and left axes with four ticks, and render them in axis groups using the call method.
Format and style D3.js axes with CSS, apply D3 time format to x-axis dates, and use tick format to show meters on the y-axis while rotating labels for readability.
Learn to plot data with d3.js by binding data to circle elements using enter, update, and exit selections, with a time-based x axis and distance-based y axis, pulling from Firestore.
Add dummy data to the graph by simulating different days through clock changes, enter daily exercise distances for cycling, running, swimming, and more, then learn to filter by activity.
Filter the graph data by activity using a Firestore-stored activity property, updating the D3.js graph on each button click to show only the selected activity.
Use D3's line path generator to draw a line graph from filtered Firebase data, mapping x to date and y to distance, and sorting by date for proper plotting.
Animate data point hover in the D3.js graph by enlarging circles on mouseover and restoring them on mouseleave, using transitions, radius changes, and a white fill.
Create a hover effect in D3.js that reveals two dotted lines from data points to the x and y axes, using a group and lines whose visibility toggles on hover.
Create dotted lines on hover in a d3.js chart by adding a hidden group with x dotted line and y dotted line and toggling its opacity via mouseover and mouseleave.
Explore building a line graph with d3, featuring interactive hover, dynamic data updates, and on-the-fly filtering and sorting, plus the essentials of enter, update, and exit patterns.
Learn how to create great-looking data visualizations with D3.js
D3.js is a powerful JavaScript library used to create data visualizations easily. In this course I'll teach you how to harness the power of D3 to create a variety of different data-driven visualizations such as bar charts, pie charts, line graphs, bubble packs and tree diagrams.
We'll learn about D3 select, changing SVG attributes & styles, scales, axes, transitions, hierarchial data and much more...
Use Firebase Firestore to update your D3.js diagrams in real-time
I'll also teach you how to use Firestore (from Google Firebase) - a real-time NoSQL database in which we can store our data. We'll use this to power our D3.js visualizations in real-time (without updating the browser) and to make them interactive, fun & dynamic.
We'll also be creating 3 projects to put our D3 & Firebase skills to the test - first of all a money planner called Ninja Wonga, then a fitness tracker called The Dojo and finally a company employee tree diagram called Ninja Corp.
...Why all the ninjas?
I'm also known as the Net Ninja on YouTube, with over 200,000 subscribers and nearly 1000 free development tutorials. Feel free to check out my teaching style there before you a buy my course :).