scalePoint example.
From D3 in Depth book by Peter Cook.
license: gpl-3.0 | |
height: 90 | |
border: no |
scalePoint example.
From D3 in Depth book by Peter Cook.
<!DOCTYPE html> | |
<meta charset="utf-8"> | |
<head> | |
<title>Point scale</title> | |
</head> | |
<style> | |
body { | |
font-family: "Helvetica Neue", Helvetica, sans-serif; | |
font-size: 14px; | |
color: #333; | |
} | |
circle { | |
fill: orange; | |
} | |
</style> | |
<body> | |
<svg width="700" height="80"> | |
<g id="wrapper" transform="translate(40, 40)"> | |
</g> | |
</svg> | |
<script src="https://cdnjs.cloudflare.com/ajax/libs/d3/4.2.2/d3.min.js"></script> | |
<script> | |
var myData = [ | |
{day : 'Mon', value: 10}, | |
{day : 'Tue', value: 40}, | |
{day : 'Wed', value: 30}, | |
{day : 'Thu', value: 60}, | |
{day : 'Fri', value: 30} | |
]; | |
var pointScale = d3.scalePoint() | |
.domain(['Mon', 'Tue', 'Wed', 'Thu', 'Fri']) | |
.range([0, 600]); | |
d3.select('#wrapper') | |
.selectAll('circle') | |
.data(myData) | |
.enter() | |
.append('circle') | |
.attr('cx', function(d) { | |
return pointScale(d.day); | |
}) | |
.attr('r', 4); | |
</script> | |
</body> | |
</html> |