Skip to content
Related Articles

Related Articles

D3.js log.range() Function
  • Last Updated : 23 Aug, 2020

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)
My Personal Notes arrow_drop_up
Recommended Articles
Page :