D3.js scaleThreshold() Function Last Updated : 31 Aug, 2020 Comments Improve Suggest changes Like Article Like Report The d3.scaleThreshold() function in D3.js is used to create and return a new threshold scale that has the specified domain and range. The default value of domain is [0.5] and that of range is [0, 1]. Syntax: d3.scaleThreshold( domain, range ) Parameters: This function accepts two parameters as given above and described below: domain: It defines the minimum and maximum value for the scale. It is an optional parameter. The default value is [0.5].range: It accepts a range of discrete values, Every value in domain maps with a value in the range. It is an optional parameter. The default range is [0, 1]. Return Values: This function does not return anything. Below programs illustrate the d3.scaleThreshold() function in D3.js: Example 1: HTML <!DOCTYPE html> <html> <head> <script src="https://d3js.org/d3.v4.min.js"> </script> </head> <body> <h2 style="color: green;">GeekforGeeks</h2> <p>d3.scaleThreshold() Function </p> <script> var threshold = d3.scaleThreshold() // Setting domain and range for the scale .domain([10]) .range(["red", "green", "black", "blue"]); document.write("<h4>" + threshold(9) + "</h4>"); document.write("<h4>" + threshold(10) + "</h4>"); </script> </body> </html> Output: Example 2: HTML <!DOCTYPE html> <html> <head> <script src="https://d3js.org/d3.v4.min.js"> </script> </head> <body> <h2 style="color: green;">GeekforGeeks</h2> <p>d3.scaleThreshold() Function </p> <script> var threshold = d3.scaleThreshold() // Setting domain and range for the scale .domain([1, 2, 10]) .range([0, 1, 2, 3]); document.write("<h4>" + threshold(2) + "</h4>"); document.write("<h4>" + threshold(10) + "</h4>"); </script> </body> </html> Output: Comment More infoAdvertise with us Next Article D3.js scaleThreshold() Function T tarun007 Follow Improve Article Tags : JavaScript Web Technologies D3.js Similar Reads D3.js threshold.range() Function The threshold.range() function is used to set the range of the threshold scale. The number of values in range array is always one greater than the domain array, if not then the behavior of the scale may be undefined. Syntax: threshold.range([range]); Parameters: This function accepts single paramete 2 min read D3.js threshold.copy() Function The threshold.copy() function in d3.js is used to create and return the exact copy of the threshold scale. Any change in the original scale will not affect the copy scale. Syntax: threshold.copy(); Parameters: This function does not accept any parameter. Return Value: This function returns an exact 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 transform.scale() Function The transform.scale() function in D3.js library is used to get the transformation whose scale kâ is equal to kâk, where kâ is the transformâs scale.Syntax: transform.scale(k)Parameters: This function accepts a single parameter as mentioned above and described below.k: This parameter is the scale arg 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 Like