Open In App

D3.js | d3.scaleIdentity() Function

Last Updated : 12 Feb, 2021
Improve
Improve
Like Article
Like
Save
Share
Report

The d3.scaleIdentity() function in D3.js is used to construct a new identity scale with the unit domain [0, 1] and the unit range [0, 1].
Syntax: 
 

d3.scaleIdentity().domain(array of values).range(array of values);

Parameters: This function does not accept any parameters.
Return Value: This function returns the corresponding range for the domain’s value. 
Below program illustrate the d3.scaleIdentity() function in D3.js:
Example: 
 

javascript




<!DOCTYPE html>
<html>
 
<head>
    <title></title>
    <script src="https://d3js.org/d3.v4.min.js">
  </script>
</head>
 
<body>
 
    <script>
        // Calling the scaleIdentity() function
        var A = d3.scaleIdentity()
            .domain([0, 1])
            .range([0, 1]);
 
        // Getting the corresponding range for
        // the domain value
        console.log(A('0'));
        console.log(A('1'));
    </script>
</body>
 
</html>


Output: 
 

0
1

Reference: https://devdocs.io/d3~5/d3-scale#scaleBand
 


Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads