Skip to content
Related Articles

Related Articles

Improve Article

D3.js | d3.lab() Function

  • Last Updated : 14 Aug, 2020

The d3.lab() function in D3.js is used to construct a new Lab color and returns ‘l’, ‘a’ and ‘b’ properties of the specified color taken as the parameter of the function.

Syntax:

d3.lab(color);

Parameters: This function accepts single parameter color which is specified CSS color.

Return Value: This function returns ‘l’, ‘a’ and ‘b’ properties of the specified CSS color taken as the parameter of the function.

Below programs illustrate the d3.lab() function in D3.js:



Example 1:




<!DOCTYPE html>
<html>
  
<head>
    <title>d3.lab() function</title>
  
    <script src='https://d3js.org/d3.v4.min.js'></script>
</head>
  
<body>
    <script>
          
        // Calling the d3.lab() function
        // with some parameters
        var color1 = d3.lab("red");
        var color2 = d3.lab("green");
        var color3 = d3.lab("blue");
        
        // Getting the LAB properties
        console.log(color1);
        console.log(color2);
        console.log(color3);
    </script>
</body>
  
</html>

Output:

{"l":53.24079414130722, "a":80.09245959641109, "b":67.20319651585301, "opacity":1}
{"l":46.22743146876261, "a":-51.69849552989111, "b":49.8968460010561, "opacity":1}
{"l":32.297010932850725, "a":79.18751984512224, "b":-107.8601617541481, "opacity":1}

Example 2:




<!DOCTYPE html>
<html>
  
<head>
    <title>d3.lab() function</title>
  
    <script src='https://d3js.org/d3.v4.min.js'></script>
</head>
  
<body>
    <script>
          
        // Calling the d3.lab() function
        // without any parameters
        var color = d3.lab();
        
        // Getting the LAB values
        console.log(color);
    </script>
</body>
  
</html>

Output:

{"l":null, "a":null, "b":null, "opacity":1}

Reference: https://devdocs.io/d3~5/d3-color#lab




My Personal Notes arrow_drop_up
Recommended Articles
Page :