D3.js中的areaRadial.context()方法可讓您指定將在其中渲染徑向區域的畫布元素的上下文。調用生成器時,將在當前上下文中渲染徑向區域。我們可以使用這種方法(例如顏色,筆觸,填充等)自行設置區域的上下文。默認值為null。
用法:
d3.areaRadial.context( _context )
參數:此方法接受如上所述和以下描述的單個參數:
- _context:它是用戶設置的上下文。
返回值:此方法返回當前上下文。
下麵給出的是D3.js中areaRadial.context()方法的一些示例:
範例1:
HTML
<!DOCTYPE html>
<html>
<head>
<script src=
"https://d3js.org/d3.v5.min.js">
</script>
</head>
<body>
<h1 style="text-align:center;
color:green;">
GeeksforGeeks
</h1>
<h3 style="text-align:center;">
D3.js | areaRadial.context() Method
</h3>
<center>
<canvas id="gfg" width="200" height="200">
</canvas>
</center>
<script>
var points = [
{ x:0, y:0 },
{ x:2, y:3 },
{ x:4, y:1 },
{ x:6, y:8 },
{ x:8, y:17 },
{ x:10, y:15 },
{ x:12, y:20 }];
// Get the context
var context = d3.select("#gfg")
.node()
.getContext("2d");
var xScale = d3.scaleLinear()
.domain([0, 6])
.range([0, 2 * Math.PI]);
var yScale = d3.scaleLinear()
.domain([0, 20])
.range([90, 30]);
var Gen = d3.areaRadial()
.angle(d => xScale(d.x / 2))
.innerRadius(d => yScale(d.y) / 2)
.outerRadius(d => yScale(d.y))
// Specify the context
// to be used
.context(context);
context.translate(100, 100);
Gen(points);
context.strokeStyle = "black";
context.fillStyle = "green";
context.fill();
context.stroke();
</script>
</body>
</html>
輸出:
範例2:
HTML
<!DOCTYPE html>
<html>
<head>
<script src=
"https://d3js.org/d3.v5.min.js">
</script>
</head>
<body>
<h1 style="text-align:center;
color:green;">
GeeksforGeeks
</h1>
<h3 style="text-align:center;">
D3.js | areaRadial.context() Method
</h3>
<center>
<canvas id="gfg" width="200" height="200">
</canvas>
</center>
<script>
var data = [
{ x:10, y:1 },
{ x:15, y:3 },
{ x:20, y:5 },
{ x:25, y:7 },
{ x:30, y:9 },
{ x:35, y:11 },
{ x:40, y:13 }];
// Get the context
var context = d3.select("#gfg")
.node()
.getContext("2d");
var xScale = d3.scaleLinear()
.domain([0, 6])
.range([0, 2 * Math.PI]);
var yScale = d3.scaleLinear()
.domain([0, 20])
.range([90, 30]);
var Gen = d3.areaRadial()
.angle(d => xScale(d.x / 2))
.innerRadius(d => yScale(d.y) / 2)
.outerRadius(d => yScale(d.y))
// Specify the context
// to be used
.context(context);
context.translate(100, 100);
Gen(data);
context.strokeStyle = "black";
context.fillStyle = "green";
context.fill();
context.stroke();
</script>
</body>
</html>
輸出:
相關用法
- Lodash _.method()用法及代碼示例
- Javascript dataView.getInt16()用法及代碼示例
- Javascript RegExp toString()用法及代碼示例
- Node.js URLSearchParams.has()用法及代碼示例
- JavaScript Math cosh()用法及代碼示例
- HTML DOM isEqualNode()用法及代碼示例
- JavaScript Date toLocaleTimeString()用法及代碼示例
- Node.js crypto.createHash()用法及代碼示例
- Node.js writeStream.clearLine()用法及代碼示例
- Javascript Number isSafeInteger()用法及代碼示例
- HTML DOM History go()用法及代碼示例
- Node.js fs.link()用法及代碼示例
- JavaScript Math random()用法及代碼示例
- JavaScript Math round()用法及代碼示例
- Javascript toString()用法及代碼示例
- Javascript Number.isInteger( )用法及代碼示例
- Javascript Number.isFinite()用法及代碼示例
- Javascript toFixed()用法及代碼示例
注:本文由純淨天空篩選整理自taran910大神的英文原創作品 D3.js areaRadial.context() Method。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。