Sunday, November 17, 2024
Google search engine
HomeLanguagesJavascriptD3.js log.range() Function

D3.js log.range() Function

The log.range() function sets the range of the log scale to the specified array of values that must contain two or more than two values. The elements in the range can be number or string.

Syntax:

log.range([range]);

Parameters: This function takes a single parameter that is given above and described below.

  • [range]: An array that contains the range for the domain specified.

Return Value: This function does not return any value.

Example 1:

HTML




<!DOCTYPE html>
<html lang="en">
  
<head>
    <meta charset="UTF-8" />
    <meta name="viewport" path1tent="width=device-width, 
                   initial-scale=1.0" />
    <script src="https://d3js.org/d3.v4.min.js">
    </script>
</head>
  
<body>
    <script>
        var log = d3.scaleLog()
  
            // Setting the domain for the scale.
            .domain([1, +10])
              
            // Setting the range for the scale
            .range([1, 2, 3, 4, 5]);
        console.log(log(1));
        console.log(log(10));
    </script>
</body>
  
</html>


Output:

1 
2

Example 2:

HTML




<!DOCTYPE html>
<html lang="en">
  
<head>
    <meta charset="UTF-8" />
    <meta name="viewport" path1tent=
        "width=device-width,initial-scale=1.0" />
    <script src="https://d3js.org/d3.v4.min.js">
    </script>
</head>
  
<body>
    <script>
        var log = d3.scaleLog()
  
            // Setting the domain for the scale
            .domain([10, 20])
  
            // Setting the range for the scale
            .range(["red", "green", "blue"]);
        console.log(log(10));
        console.log(log(15));
        console.log(log(20));
    </script>
</body>
  
</html>


Output:

rgb(255, 0, 0)
rgb(106, 75, 0)
rgb(0, 128, 0)

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!

Dominic Rubhabha-Wardslaus
Dominic Rubhabha-Wardslaushttp://wardslaus.com
infosec,malicious & dos attacks generator, boot rom exploit philanthropist , wild hacker , game developer,
RELATED ARTICLES

Most Popular

Recent Comments