D3
= Data-Driven Documents
A library that provides a mechanism for connecting arbitrary data to documents (DOM elements), allowing the appearance and behaviour of the documents. to be driven by the data.
VISUALISATION is provided by HTML, CSS, or SVG, D3 focuses on the DATA. It is actually a collection of integrated JS tools for manipulating data structures necessary to create data visualisations.
How does D3 work?
DATA drives documents that display D3 visualisations. By ADDING, CHANGING, or REMOVING data, you directly affect the way your chart appears on the screen.
Typical D3 Script
D3’s actual data visualisation part
Contains tools that are applied to previously selected DOM nodes and data:
What does d3’s .data() do?
Sets the data to drive creation of the elements.
What does d3’s .enter() do?
Creates a selection to add elements per data item.
It binds the data to the selection of elements creating the array of placeholders of the same size as the data array.
When is d3’s .transition() called?
Before the attributes and styles that are to be changed.
Which d3 modules are enough to create an animated interactive bar chart?
- transition
What categories of d3 modules exist?
Modules for:
When to use canvas in D3?
Use it in all or part of your app
-> if you have memory problems due to excessive objects created in the DOM
HTML canvas how to
const ctx = canvas.getContext(‘2d’)
ctx. fillStyle = ‘red’;
ctx. lineWidth=’10’;
ctx. fillRect(50,50,50,50);
ctx. strokeRect(50,50,50,50):