D3.js scaleOrdinal() Function Last Updated : 18 Sep, 2020 Summarize Comments Improve Suggest changes Share Like Article Like Report The d3.scaleOrdinal() function is used to create and return the ordinal scale which has the specified range and domain. If the domain and range are not given then both are set to empty array. These types of scales have a discrete domain and range. Syntax: d3.scaleOrdinal([[domain, ]range]); Parameters: This function takes two parameters as given above and described below: domain: It defines the minimum and maximum value for the scale.range: Every value in domain maps with value in the range. Return Values: This function does not return anything. 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> // Creating the Ordinal scale. var ordinal = d3.scaleThreshold() // Setting domain for the scale .domain([1, 2, 3, 4]) .range([10, 20, 30, 40]); console.log("The value of ordinal(1) is: ", ordinal(1)); console.log("The value of ordinal(2) is: ", ordinal(2)); console.log("The value of ordinal(3) is: ", ordinal(3)); </script> </body> </html> Output: 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> // Creating the Ordinal scale. var ordinal = d3.scaleThreshold() // Setting domain for the scale .domain([1, 2, 3, 4]) .range(["String1", "string2", "string3", "string4"]); console.log("The value of ordinal(1) is: ", ordinal(1)); console.log("The value of ordinal(2) is: ", ordinal(2)); console.log("The value of ordinal(3) is: ", ordinal(3)); console.log("When value given is not" + " in the domain:") console.log("The value of ordinal(4) is: ", ordinal(10)); </script> </body> </html> Output: Comment More infoAdvertise with us Next Article D3.js scalePoint() Function T tarun007 Follow Improve Article Tags : JavaScript Web Technologies D3.js Similar Reads D3.js scalePoint() Function The d3.scalepoint() function is used to create and return a new point scale with a particular domain and range, no rounding, no padding, and center alignment. Syntax: d3.scalePoint([[domain, ]range]); Parameters: This function takes two parameters as given above and described below: domain: It defin 2 min read D3.js scaleOrdinal ordinal() Function The ordinal() function in d3.js library is used to return a value from the specified range on giving an input corresponding to the specified domain. Syntax: ordinal(value); Parameters: This function accepts a single parameter as given above and described below. Value: This parameter accepts a value 2 min read D3.js scalePow() Function The d3.scalePow() function is used to create and return a new continuous scale. This scale has a specified domain and range. Generally, it acts as a linear scale but when used with exponent it works in a different way. Syntax: d3.scalePow([[domain, ]range]); Parameters: This function accepts two par 2 min read D3.js scaleLog() Function The d3.scaleLog() function is used to create a new continuous scale with the user-defined domain and range, the default base is 10. clamping is disabled by default in this scale. Syntax: d3.scaleLog([[domain, ]range]) Parameters: This function accepts two parameters as mentioned above and described 2 min read D3.js scaleTime() Function The d3.scaleTime() function is used to create and return a new time scale which have the particular domain and range. In this function the clamping is disabled by default. Syntax: d3.scaleTime([[domain, ]range]); Parameter: This function accepts two parameters as mentioned above and described below. 2 min read D3.js ordinal.copy() Function The ordinal.copy() function is used to create and return the exact copy of the ordinal scale. Any change in the original scale will not affect the copy scale and vice-versa. Syntax: ordinal.copy(); Parameters: This method does not take any parameters. Return Values: This method returns a copy of the 2 min read Like