Built with blockbuilder.org
Last active
January 3, 2020 16:19
-
-
Save e1jo/b289a75e3168e18f43b70cbefda71856 to your computer and use it in GitHub Desktop.
d3-test-3 scale
This file contains hidden or 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: mit |
This file contains hidden or 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> | |
<head> | |
<meta charset="utf-8"> | |
<script src="https://d3js.org/d3.v4.min.js"></script> | |
<style> | |
body { | |
margin:0; | |
padding: 0; | |
height: 100vh; | |
background-color: #009688b8; | |
} | |
svg { | |
width: 100%; | |
height: 100%; | |
} | |
rect { | |
fill: red; | |
} | |
</style> | |
</head> | |
<body> | |
<svg> | |
<g id="wrapper"> | |
</svg> | |
<script> | |
var data = [ | |
{day: 'Mon', value: 100}, | |
{day: 'Tue', value: 20}, | |
{day: 'Wed', value: 60}, | |
{day: 'Thu', value: 40}, | |
{day: 'Fri', value: 180}, | |
] | |
var bandScale = d3.scaleBand() | |
.domain( data.map( (el) => el.day) ) // .domain(['Mon', 'Tue', 'Wed']) | |
.range([0, 500]) | |
.paddingInner(0.05) | |
d3.select('#wrapper') | |
.selectAll('rect') | |
.data(data) | |
.enter() | |
.append('rect') | |
.attr('y', (d) => bandScale(d.day)) | |
.attr("width", (d) => d.value) | |
.attr("height", bandScale.bandwidth()) | |
</script> | |
</body> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment