Shift Data in Radial area graphs
-
-
Save johnpoole/e86fd624f967ae9192d5e70ad1693c02 to your computer and use it in GitHub Desktop.
Radial area generator
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
license: gpl-3.0 | |
height: 210 | |
border: no |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<meta charset="utf-8"> | |
<head> | |
<title>Radial area generator</title> | |
</head> | |
<style> | |
path { | |
fill: #ddd; | |
} | |
</style> | |
<body> | |
<svg width="700" height="200"> | |
<g transform="translate(100,100)"></g> | |
</svg> | |
<script src="https://cdnjs.cloudflare.com/ajax/libs/d3/4.2.2/d3.min.js"></script> | |
<script> | |
var radialAreaGenerator = d3.radialArea() | |
.angle(function(d) { | |
return d.angle; | |
}) | |
.innerRadius(function(d) { | |
return d.r0; | |
}) | |
.outerRadius(function(d) { | |
return d.r1; | |
}); | |
var points = [ | |
{angle: 0, r0: 20, r1: 80}, | |
{angle: Math.PI * 0.25, r0: 20, r1: 40}, | |
{angle: Math.PI * 0.5, r0: 20, r1: 80}, | |
{angle: Math.PI * 0.75, r0: 20, r1: 40}, | |
{angle: Math.PI, r0: 20, r1: 80}, | |
{angle: Math.PI * 1.25, r0: 20, r1: 40}, | |
{angle: Math.PI * 1.5, r0: 20, r1: 80}, | |
{angle: Math.PI * 1.75, r0: 20, r1: 40}, | |
{angle: Math.PI * 2, r0: 20, r1: 80} | |
]; | |
var pathData = radialAreaGenerator(points); | |
// Create a path element and set its d attribute | |
d3.select('g') | |
.append('path') | |
.attr('d', pathData); | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment