Skip to content

Instantly share code, notes, and snippets.

@shaneporter
Created March 13, 2018 11:29
Show Gist options
  • Save shaneporter/daeddd36bb87b31ff6fcb73516c0a549 to your computer and use it in GitHub Desktop.
Save shaneporter/daeddd36bb87b31ff6fcb73516c0a549 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 { margin:0;position:fixed;top:0;right:0;bottom:0;left:0; }
</style>
</head>
<body>
<script>
// Feel free to change or delete any of the code you see in this editor!
var width = 960,
height = 500;
var svg = d3.select("body").append("svg")
.attr("width", width)
.attr("height", height)
var data = [5, 10, 15, 20, 25, 30];
svg.selectAll('rect')
.data(data)
.enter()
.append("rect")
.attr('x', function(d,i ) {
return i * 21
})
.attr({
'y': function(d, i) { return height - d; },
'width': 20,
'height': function(d, i) { return d; },
'fill': function(d, i) {
return d >= 20 ? 'red': 'green'
}
});
</script>
</body>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment