Arc generator (using accessors).
From D3 in Depth book by Peter Cook.
license: gpl-3.0 | |
height: 230 | |
border: no |
Arc generator (using accessors).
From D3 in Depth book by Peter Cook.
<!DOCTYPE html> | |
<meta charset="utf-8"> | |
<head> | |
<title>Arc generator (using accessors)</title> | |
</head> | |
<style> | |
path { | |
fill: orange; | |
stroke: white; | |
} | |
</style> | |
<body> | |
<svg width="700" height="220"> | |
<g transform="translate(300, 110)"></g> | |
</svg> | |
<script src="https://cdnjs.cloudflare.com/ajax/libs/d3/4.2.2/d3.min.js"></script> | |
<script> | |
// Create an arc generator with configuration and accessor functions | |
var arcGenerator = d3.arc() | |
.innerRadius(20) | |
.outerRadius(100) | |
.startAngle(function(d) { | |
return d.startAngleOfMyArc; | |
}) | |
.endAngle(function(d) { | |
return d.endAngleOfMyArc; | |
}); | |
var arcData = [ | |
{startAngleOfMyArc: 0, endAngleOfMyArc: 0.2}, | |
{startAngleOfMyArc: 0.2, endAngleOfMyArc: 0.6}, | |
{startAngleOfMyArc: 0.6, endAngleOfMyArc: 1.4}, | |
{startAngleOfMyArc: 1.4, endAngleOfMyArc: 3}, | |
{startAngleOfMyArc: 3, endAngleOfMyArc: 2* Math.PI} | |
]; | |
// Create a path element and set its d attribute | |
d3.select('g') | |
.selectAll('path') | |
.data(arcData) | |
.enter() | |
.append('path') | |
.attr('d', arcGenerator); | |
</script> | |
</body> | |
</html> |