D3.js scaleQuantize() Function

The d3.scaleQuantize() function in d3.js is used to create a new scale that is similar to linear scales except that linear scales use a discrete and dis-continuous scale.

Syntax:

d3.scaleQuantize();

Parameters: This function does not accept any parameter.

Return Value: A function is returned by d3.scaleQuantize() function.

Example 1:



HTML

filter_none

edit
close

play_arrow

link
brightness_4
code

<!DOCTYPE html>
<html lang="en">
  
<head>
    <meta charset="UTF-8" />
    <meta name="viewport" path1tent="width=device-width, 
        initial-scale=1.0" />
    <title>Geeks for geeks</title>
    <script src="https://d3js.org/d3.v4.min.js">
    </script>
    <script src="https://d3js.org/d3-color.v1.min.js">
    </script>
    <script src=
    </script>
    <script src=
    </script>
  
    <style>
        body {
            line-height: 5px;
            text-align: center;
        }
  
        h2 {
            color: green;
        }
    </style>
</head>
  
<body>
    <h2>Geeks for geeks</h2>
    <p>D3.scaleQuantize() Function </p>
    <script>
        var object = d3.scaleQuantize()
            .domain([0, 1])
            .range(["less than 0.5", "greater than 0.5"]);
        document.write("<br/>")
        document.write("<h3>" + object(0.4) + "</h3>");
        document.write("<h3>" + object(0.5) + "</h3>");
    </script>
</body>
  
</html>

chevron_right


Output:

Example 2:

HTML

filter_none

edit
close

play_arrow

link
brightness_4
code

<!DOCTYPE html>
<html lang="en">
  
<head>
    <meta charset="UTF-8" />
    <meta name="viewport" path1tent="width=device-width, 
        initial-scale=1.0" />
    <title>Geeks for geeks</title>
    <script src="https://d3js.org/d3.v4.min.js">
    </script>
    <script src="https://d3js.org/d3-color.v1.min.js">
    </script>
    <script src=
    </script>
    <script src=
    </script>
  
    <style>
        body {
            line-height: 5px;
            text-align: center;
        }
  
        h2 {
            color: green;
        }
    </style>
</head>
  
<body>
    <h2>Geeks for geeks</h2>
    <p>D3.scaleQuantize() Function </p>
    <script>
        var object = d3.scaleQuantize()
  
            // Value from 1 to 10 decides 
            // which value to output
            .domain([1, 10])
            .range(["1. This is object(1)",
                "2. This is object(2)",
                "3. This is object(3)",
                "4. This is object(4)",
                "5. This is object(5)",
                "6. This is object(6)",
                "7. This is object(7)",
                "8. This is object(8)",
                "9. This is object(9)",
                "10. This is object(10)"]);
                  
        document.write("<br/>")
        document.write("<h3>" + object(1) + "</h3>");
        document.write("<h3>" + object(2) + "</h3>");
        document.write("<h3>" + object(3) + "</h3>");
        document.write("<h3>" + object(4) + "</h3>");
        document.write("<h3>" + object(5) + "</h3>");
        document.write("<h3>" + object(6) + "</h3>");
        document.write("<h3>" + object(7) + "</h3>");
        document.write("<h3>" + object(8) + "</h3>");
        document.write("<h3>" + object(9) + "</h3>");
        document.write("<h3>" + object(10) + "</h3>");
    </script>
</body>
  
</html>

chevron_right


Output:

full-stack-img




My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.


Article Tags :

Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.