Skip to content

Instantly share code, notes, and snippets.

@voigtd
Last active August 10, 2017 00:31
Show Gist options
  • Save voigtd/05a23498b61e5938d4e2f4dee69fca14 to your computer and use it in GitHub Desktop.
Save voigtd/05a23498b61e5938d4e2f4dee69fca14 to your computer and use it in GitHub Desktop.
mike bostock - bar chart pt. 1
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; }
.chart div {
font: 10px sans-serif;
background-color: steelblue;
text-align: right;
padding: 3px;
margin: 1px;
color: white;
}
</style>
</head>
<body>
<div class='chart'></div>
<script>
let data = [4, 8, 15, 16, 23, 42];
let xScale = d3.scaleLinear()
.domain([0, d3.max(data)])
.range([0, 420]);
d3.select('.chart')
.selectAll('div')
.data(data)
.enter().append('div')
.style('width', d => xScale(d) + 'px')
.text(d => d);
</script>
</body>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment