Continuous.tickFormat()函數用於更改刻度值的格式。它返回一個適合顯示刻度值的數字格式函數。
用法:
continuous.tickFormat( count, specifier )
參數:該函數接受上麵提到和下麵描述的兩個參數。
- count:它是要使用的刻度值的數量。它是一個可選參數。
- specifier:它是一個字符串,指定要使用的格式。它是一個可選參數。
返回值:此函數不返回任何內容。
以下示例程序旨在說明D3.js中的Continuous.tickFormat()函數:
範例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>continuous.tickFormat() Function </p>
<script>
var x = d3.scaleLinear()
.domain([0, 1])
.range([1, 2, 3, 4, 5, 6]);
var ticks = x.ticks(3)
var tickFormat = x.tickFormat(3, " %");
document.write("<h3>" +
ticks.map(tickFormat) +
"</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>continuous.tickFormat() Function </p>
<script>
var x = d3.scaleLinear()
.domain([0, 1])
.range(["red", "blue", "green", "orange"]);
var ticks = x.ticks(5)
var tickFormat = x.tickFormat(5, " $");
document.write("<h3>" +
ticks.map(tickFormat) +
"</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 continuous.tickFormat() Function。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。