d3.scaleLog()函數用於創建具有用戶定義的域和範圍的新連續刻度,默認基數為10。默認情況下,此刻度禁用夾緊。
用法:
d3.scaleLog([[domain, ]range])
參數:該函數接受上麵提到和下麵描述的兩個參數。
- domain:此參數始終接受兩個或兩個以上的數字。默認值為[1,10]。
- range:此參數接受數字或字符串數組。默認值為[0,1]。
返回值:此函數返回新創建的連續刻度。
下麵給出的是上麵給出的函數的一些例子。
範例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>
var log = d3.scaleLog()
.domain([1, 10])
.range([10, 20, 30, 40, 50, 60]);
console.log(log(1));
console.log(log(2));
console.log(log(3));
console.log(log(4));
</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>
var log = d3.scaleLog()
.domain([-1, 1])
.range([10, 20, 30, 40, 50, 60]);
// Returns NaN as Domain cant be less than one
console.log("Domain in log scale cannot"
+ " be less than one:", log(1));
var log = d3.scaleLog()
.domain([10, 100])
.range(["red", "green", "blue", "white"]);
console.log("log(1):", log(1));
console.log("log(1.5):", log(1.5));
</script>
</body>
</html>
輸出:
相關用法
- PHP chr()用法及代碼示例
- PHP Ds\Map xor()用法及代碼示例
- PHP abs()用法及代碼示例
- PHP Ds\Map put()用法及代碼示例
- CSS var()用法及代碼示例
- d3.js d3.min()用法及代碼示例
- p5.js sq()用法及代碼示例
- d3.js d3.max()用法及代碼示例
- p5.js pow()用法及代碼示例
- p5.js max()用法及代碼示例
- d3.js zip()用法及代碼示例
- p5.js second()用法及代碼示例
- p5.js day()用法及代碼示例
- d3.js d3.rgb()用法及代碼示例
- d3.js d3.map.set()用法及代碼示例
注:本文由純淨天空篩選整理自tarun007大神的英文原創作品 D3.js scaleLog() Function。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。