d3.js中的band.domain()函数用于设置音阶域。域中存在的第一个值将映射到范围数组中的第一个波段,依此类推。
用法:
band.domain([domain]);
参数:该函数接受上面给定和下面描述的单个参数。
- domain:此参数设置刻度的范围,即最小值和最大值。
返回值:此函数不返回任何内容。
范例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>
// Create band scale with domain
// and range
var band = d3.scaleBand()
// Setting domain for the scale
.domain(["redcolor", "greencolor",
"blackcolor", "bluecolor"]);
console.log("band(redcolor):",
band("redcolor"));
console.log("band(blackcolor):",
band("blackcolor"));
console.log("band(greencolor):",
band("greencolor"));
console.log("band(bluecolor):",
band("bluecolor"));
</script>
</body>
</html>
输出:
范例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 band scale with
// specified domain and range.
var band = d3.scaleBand()
// Setting domain for the scale
.domain([10, 20, 30, 40])
.range([0, 11]);
console.log("band(10):", band(10));
console.log("band(20):", band(20));
console.log("band(30):", band(30));
console.log("band(40):", band(40));
</script>
</body>
</html>
输出:
相关用法
- PHP imagecreatetruecolor()用法及代码示例
- p5.js year()用法及代码示例
- d3.js d3.utcTuesdays()用法及代码示例
- PHP ImagickDraw getTextAlignment()用法及代码示例
- PHP Ds\Sequence last()用法及代码示例
- PHP array_udiff_uassoc()用法及代码示例
- PHP geoip_continent_code_by_name()用法及代码示例
- d3.js d3.map.set()用法及代码示例
- PHP GmagickPixel setcolor()用法及代码示例
- PHP opendir()用法及代码示例
- PHP cal_to_jd()用法及代码示例
- d3.js d3.bisectLeft()用法及代码示例
- PHP stream_get_transports()用法及代码示例
- PHP Ds\Deque pop()用法及代码示例
注:本文由纯净天空筛选整理自tarun007大神的英文原创作品 D3.js band.domain() Function。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。