The pow.domain() function is used to set the scale’s domain to the specified array of numbers. The array specified here must contain two or more than two elements.
Syntax:
pow.domain([domain]);
Parameters: This function takes a single parameter that is given above and described below.
- [domain]: An array that takes two or more values that specify the domain.
Return Value: This function does not return any value.
Example 1:
<!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 pow = d3.scalePow()
// Setting domain for the scale.
.domain([10, 20])
.range(["1", "2", "3", "4", "5"])
.exponent(2);
console.log("The domain of this is [10,20]: ");
console.log("pow(10): " + pow(10));
console.log("pow(11): " + pow(11));
console.log("pow(12): " + pow(12));
</script>
</body>
</html>
Output:
Example 2:
<!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>
<style>
</style>
<body>
<script>
var pow = d3.scalePow()
// Setting domain for the scale.
.domain([-1, 1])
.range(["red", "blue", "green", "white"])
.exponent(2);
console.log("The domain of this is [-1,1]: ");
console.log("pow(-1): " + pow(-1));
console.log("pow(0): " + pow(0));
console.log("pow(1): " + pow(1));
</script>
</body>
</html>
Output: