d3.InterpolateRound()函數用於返回兩個給定數字的插值並將它們四舍五入為最接近的整數。
用法:
d3.interpolateRound(a,b)
參數:該函數接受上述兩個參數,並在下麵進行描述。
- a:它是任何數字。
- b:它是任何數字。
返回值:它返回插值器函數。
下麵給出了一些Interpolate.Round()函數的示例。
範例1:
HTML
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport"
content="width=device-width, initial-scale=1.0">
<title>D3.js d3.interpolateRound() Function</title>
</head>
<style>
</style>
<body>
<!--Fetching from CDN of D3.js -->
<script type = "text/javascript" src =
"https://d3js.org/d3.v4.min.js">
</script>
<script>
console.log("Type is:",typeof(d3.interpolateRound(4,5)))
console.log(d3.interpolateRound(-2636,586)(0.2))
console.log(d3.interpolateRound(3545,96.485)(0.6))
console.log(d3.interpolateRound(24.1545,458)(0.2))
</script>
</body>
</html>
輸出:
範例2:當傳遞數字以外的任何東西時。
HTML
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport"
content="width=device-width, initial-scale=1.0">
<title>D3.js d3.interpolateRound() Function</title>
</head>
<style>
</style>
<body>
<!--Fetching from CDN of D3.js -->
<script type = "text/javascript" src =
"https://d3js.org/d3.v4.min.js">
</script>
<script>
console.log("Type is:",typeof(d3.interpolateRound(4,5)))
console.log(d3.interpolateRound([1,2,3],[2,3,4])(0.2))
console.log(d3.interpolateRound(3545,"green")(0.6))
console.log(d3.interpolateRound("green","red")(0.2))
console.log(d3.interpolateRound(245889,)(0.2))
</script>
</body>
</html>
輸出:
相關用法
- d3.js d3.set.add()用法及代碼示例
- PHP Ds\Set add()用法及代碼示例
- p5.js nfs()用法及代碼示例
- p5.js nfp()用法及代碼示例
- PHP next()用法及代碼示例
- d3.js d3.map.set()用法及代碼示例
- p5.js nf()用法及代碼示例
- p5.js nfc()用法及代碼示例
- PHP each()用法及代碼示例
- p5.js box()用法及代碼示例
- PHP Ds\Map xor()用法及代碼示例
- PHP max( )用法及代碼示例
- PHP Ds\Map get()用法及代碼示例
- CSS url()用法及代碼示例
- d3.js d3.mean()用法及代碼示例
注:本文由純淨天空篩選整理自tarun007大神的英文原創作品 D3.js interpolateRound() Function。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。