Sunday, November 17, 2024
Google search engine
HomeLanguagesJavascriptD3.js | d3.cubehelix() Function

D3.js | d3.cubehelix() Function

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

Whether you’re preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, neveropen Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we’ve already empowered, and we’re here to do the same for you. Don’t miss out – check it out now!

RELATED ARTICLES

Most Popular

Recent Comments