D3.js中的time.copy()函數用於構造並返回原始比例的副本。對原始比例進行的更改不會影響複印比例,反之亦然。
用法:
time.copy()
參數:此函數不接受任何參數。
返回值:此函數返回原始比例的副本。
以下示例程序旨在說明D3.js中的time.copy()函數:
範例1:
HTML
<!DOCTYPE html>
<html>
<head>
<script src="https://d3js.org/d3.v4.min.js">
</script>
<script src="https://d3js.org/d3-color.v1.min.js">
</script>
<script src=
"https://d3js.org/d3-interpolate.v1.min.js">
</script>
<script src=
"https://d3js.org/d3-scale-chromatic.v1.min.js">
</script>
</head>
<body>
<h1 style="color:green;">GeeksforGeeks</h1>
<p>time.copy() Function </p>
<script>
var time = d3.scaleTime()
// Setting domain and range
// for the scale
.domain([1, 100])
.range([1, 10]);
// Creating a copy of the scale
var copy = time.copy();
document.write("<h3>time(1):" +
time(1) + "</h3>");
document.write("<h3>time(100):" +
time(100) + "</h3>");
document.write("<p> copy scale:</p>");
document.write("<h3>copy(100):" +
copy(100) + "</h3>");
document.write("<h3>copy(1):" +
copy(1) + "</h3>");
</script>
</body>
</html>
輸出:
範例2:
HTML
<!DOCTYPE html>
<html>
<head>
<script src="https://d3js.org/d3.v4.min.js">
</script>
<script src="https://d3js.org/d3-color.v1.min.js">
</script>
<script src=
"https://d3js.org/d3-interpolate.v1.min.js">
</script>
<script src=
"https://d3js.org/d3-scale-chromatic.v1.min.js">
</script>
</head>
<body>
<h1 style="color:green;">GeeksforGeeks</h1>
<p>time.copy() Function </p>
<script>
var time = d3.scaleTime()
// Setting domain and range
// for the scale.
.domain([1, 100])
.range([1, 10]);
// Creating a copy of the scale
var copy = time.copy();
document.write("<h3>time(1000):" +
time(1000) + "</h3>");
document.write("<h3>time(100000):" +
time(10000) + "</h3>");
// Using clamp on the copy of the scale
document.write(
"<p> copy scale with clamp function.</p>");
copy.clamp(true);
document.write("<h3>copy(1000):" +
copy(1000) + "</h3>");
document.write("<h3>copy(10000):" +
copy(10000) + "</h3>");
</script>
</body>
</html>
輸出:
相關用法
- PHP Ds\Set add()用法及代碼示例
- PHP each()用法及代碼示例
- PHP Ds\Map put()用法及代碼示例
- PHP Ds\Set first()用法及代碼示例
- PHP Ds\Set last()用法及代碼示例
- d3.js d3.map.set()用法及代碼示例
- p5.js pan()用法及代碼示例
- p5.js value()用法及代碼示例
- PHP Ds\Map xor()用法及代碼示例
- PHP Ds\Set contains()用法及代碼示例
- PHP Ds\Set xor()用法及代碼示例
- d3.js lch()用法及代碼示例
- d3.js d3.max()用法及代碼示例
- p5.js hue()用法及代碼示例
- p5.js min()用法及代碼示例
- p5.js red()用法及代碼示例
注:本文由純淨天空篩選整理自tarun007大神的英文原創作品 D3.js time.copy() Function。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。