Skip to content

Instantly share code, notes, and snippets.

@bigandy
Last active January 10, 2018 17:20
Show Gist options
  • Save bigandy/afa1694c6e2361aaa7ee8da5317c2ec4 to your computer and use it in GitHub Desktop.
Save bigandy/afa1694c6e2361aaa7ee8da5317c2ec4 to your computer and use it in GitHub Desktop.
fresh block
license: mit
<!DOCTYPE html>
<head>
<meta charset="utf-8">
<script src="https://d3js.org/d3.v4.min.js"></script>
<style>
body {
display: flex;
/* justify-content: center; */
align-items: center;
min-height: 100vh;
}
svg {
overflow: visible;
}
</style>
</head>
<body>
<svg></svg>
<script>
var data = [10, 40, 200, 150, 250, 150];
var rectWidth = 100;
var height = 100;
var svg = d3.select('svg');
svg.selectAll('rect')
.data(data)
.enter().append('rect')
.attr('x', (d, i) => i * rectWidth)
.attr('y', d => {
return height - d;
})
.attr('width', rectWidth)
.attr('height', d => d)
.attr('fill', (d) => {
if (d >= 100) {
return 'blue';
} else {
return 'red';
}
})
.attr('stroke', 'white')
</script>
</body>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment