Skip to content

Instantly share code, notes, and snippets.

@4xDMG
Last active May 18, 2017 10:01
Show Gist options
  • Save 4xDMG/9a08b9f4bab46b1e94a6dfc25250884a to your computer and use it in GitHub Desktop.
Save 4xDMG/9a08b9f4bab46b1e94a6dfc25250884a 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; }
svg {height: 100%; width:100%}
</style>
</head>
<body>
<svg>
</svg>
<script>
var rectWid = 100;
var height = 300;
var data = [100, 2500, 175, 200, 120];
var yMax = d3.max(data, d => d);
var extent = d3.extent(data, d => d);
var yScale = d3.scaleLinear()
.domain([0, yMax])
.range([height, 0]);
var svg = d3.select('svg');
svg.selectAll('rect')
.data(data)
.enter().append('rect')
.attr('x', (d, i) => i * rectWid)
.attr('y', d => yScale(d))
.attr('width', rectWid)
.attr('height', d => height - yScale(d))
.attr('fill', d => d === 2500 ? 'red' :'blue')
.attr('stroke', '#fff');
</script>
</body>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment