Open In App

D3.js Introduction

The D3 is an abbreviation of Data-Driven Documents, and D3.js is a resource JavaScript library for managing documents based on data. D3 is one of the most effective frameworks to work on data visualization. It allows the developer to create dynamic, interactive data visualizations in the browser with the help of HTML, CSS, and SVG. Data visualization is the representation of filtered data in the form of pictures and graphics. Graphical or pictorial representations present even complex data sets with ease. Also, comparative analytics or patterns can be easily traced with the help of data visualization, thus enabling the client to make decisions without much brainstorming. Such visualizations can be easily developed using frameworks such as D3.js. Mike Bostock wrote the D3 framework. Before D3, the Protovis toolkit was widely used for Data Visualizations. Though there are many other frameworks for Data visualization, D3.js has left its footmark because of its flexibility and learnability.

Setting up D3.js environment: 



Step 1: In order to make the use of D3.js for a website or webpage, the first thing that needs to be taken care of is its installation or import of library into the webpage. The D3 is an open-source library. The source code is freely available on the D3.js website. Download the latest version of the library (5.7.0 currently). Download the D3 library from the source link. 

Step 2: Unzip the .zip file obtained after the completion of the download. Locate the d3.min.js file which is the minimal version of the D3 source code. Copy that file and include it in the root folder or the main library directory of the web page. In the webpage, include the d3.min.js file as shown.






<!DOCTYPE html>
<html lang="en">
 
<head>
    <!--Adding the source file of D3 here -->
    <script src="../d3.min.js"></script>
</head>
 
<body>
    <script>
        // Write your d3 code here
    </script>
</body>
 
</html>

Example: In this example, we can see that by using the d3.greatest() method, we are able to get the largest value from the sequence from an array.

Filename: index.js




// Defining d3 contrib variable
let d3 = require('d3');
 
let gfg = d3.greatest([5, 4, 3, 2, 1])
 
console.log(gfg)

Output:

5

Advantages:

Disadvantages:


Article Tags :