如果给出了范围内的值,则使用D3.js中的d3.continuous.invert()函数从域中返回相应的值。
用法:
.invert( Value )
参数:此函数接受单个参数Value,该参数保存范围的值。
返回值:如果给出了范围内的值,则此函数从域中返回相应的值。
以下程序说明了D3.js中的d3.continuous.invert()函数:
示例1:
<!DOCTYPE html>
<html>
<head>
<title>
D3.js | d3.continuous.invert() Function
</title>
<script src =
"https://d3js.org/d3.v4.min.js">
</script>
</head>
<body>
<script>
// Calling scaleLinear() function
var x = d3.scaleLinear().domain([10, 150])
.range([0, 1000]);
// Calling the .invert() function
// and getting the corresponding value
// from domain if value from range is given
console.log(x.invert(150));
console.log(x.invert(999));
</script>
</body>
</html>
输出:
31 149.86
示例2:
<!DOCTYPE html>
<html>
<head>
<title>
D3.js | d3.continuous.invert() Function
</title>
<script src =
"https://d3js.org/d3.v4.min.js">
</script>
</head>
<body>
<script>
// Calling scaleLinear() function
var x = d3.scaleLinear().domain([0, 1])
.range([10, 20]);
// Calling the .invert() function
// and getting the corresponding value
// from domain if value from range is given
console.log(x.invert(11));
console.log(x.invert(13));
console.log(x.invert(15));
console.log(x.invert(19));
</script>
</body>
</html>
输出:
0.1 0.3 0.5 0.9
参考: https://devdocs.io/d3~5/d3-scale#continuous_invert
相关用法
- p5.js cos()用法及代码示例
- d3.js d3.hsl()用法及代码示例
- p5.js log()用法及代码示例
- p5.js tan()用法及代码示例
- PHP pos()用法及代码示例
- d3.js d3.sum()用法及代码示例
- PHP key()用法及代码示例
- p5.js sin()用法及代码示例
- p5.js second()用法及代码示例
- PHP Ds\Map put()用法及代码示例
- PHP each()用法及代码示例
- PHP each()用法及代码示例
注:本文由纯净天空筛选整理自Kanchan_Ray大神的英文原创作品 D3.js | d3.continuous.invert() Function。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。