Open In App

D3.js | d3.cubehelix() Function

Last Updated : 12 Jun, 2020
Improve
Improve
Like Article
Like
Save
Share
Report

The d3.cubehelix() function in D3.js is used to construct a new Cubehelix color and returns HSL properties of the specified color taken as the parameter of the function.

Syntax:

d3.cubehelix(color);

Parameters: This function accepts single parameter color which specifies the CSS color.

Return Value: This function returns HSL properties of the specified CSS color taken as the parameter of the function.

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

Example 1:




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


Output:

{"h":351.8102617708421, "s":1.9488976453722686, "l":0.2999994453152424, "opacity":1}
{"h":109.95916521883123, "s":1.1193720244160954, "l":0.29615736727228126, "opacity":1}
{"h":236.94217167732103, "s":4.614386868039719, "l":0.10999954957200976, "opacity":1}

Example 2:




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


Output:

{"h":null, "s":null, "l":null, "opacity":1}

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



Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads