D3.js ordinal.copy() Function Last Updated : 18 Sep, 2020 Summarize Comments Improve Suggest changes Share Like Article Like Report 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 original scale. 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]); // Making copy of the scale. var ordinalCopy = ordinal.copy(); console.log("The value of ordinalCopy(1) is: ", ordinalCopy(1)); console.log("The value of ordinalCopy(2) is: ", ordinalCopy(2)); console.log("The value of ordinal(1) is: ", ordinal(1)); console.log("The value of ordinal(2) is: ", ordinal(2)); </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([10, 20, 30, 40, 50]); console.log("The value of ordinal(3) is: ", ordinal(3)); console.log("The value of ordinal(4) is: ", ordinal(4)); // Making copy of the scale. var ordinalCopy = ordinal.copy(); // making change in the original scale. ordinal.range(["The range of the " + "original scale is change"]); console.log("The value of ordinalCopy(3) is: ", ordinalCopy(3)); console.log("The value of ordinalCopy(4) is: ", ordinalCopy(4)); console.log("The value of ordinal(3) is: ", ordinal(3)); console.log("The value of ordinal(4) is: ", ordinal(4)); </script> </body> </html> Output: Comment More infoAdvertise with us Next Article D3.js pow.copy() Function T tarun007 Follow Improve Article Tags : JavaScript Web Technologies D3.js Similar Reads D3.js point.copy() Function The point.copy() function is used to construct and return the copy of the current scale. Any changes made to either scale is independent of each other i.e change in copy scale will not affect the original scale and vice-versa. Syntax: point.copy(); Parameters: This function does not accept any param 2 min read D3.js pow.copy() Function The pow.copy() function is used to create and return an exact copy of the given scale. Any change in the original scale will not affect the return scale and vice-versa. Syntax: pow.copy(); Parameters: This function does not accept any parameters. Return Values: This function returns the exact copy o 2 min read D3.js time.copy() Function The time.copy() function in D3.js is used to construct and return the copy of the original scale. Changes done to the original scale will not affect the copy scale and vice-versa. Syntax: time.copy() Parameters: This function does not accept any parameter. Return Values: This function returns the co 2 min read D3.js scaleOrdinal() Function 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]); Paramete 2 min read D3.js ordinal.range() Function The ordinal.range() function in d3.js is used to set the range for the ordinal scale. If in the range there are less number of elements as compared to domain the values then the scale reuse values of the specified range from starting. Syntax: ordinal.range([range]); Parameters: This function takes o 2 min read D3.js quantile.copy() Function The quantile.copy() function returns the exact copy of the original scale. Any changes if made in either of the scale will not affect the other scale. Syntax: quantile.copy(); Parameters: This function does not accept any parameter. Return Values: This function returns the copy of the original scale 2 min read Like