Skip to content

Instantly share code, notes, and snippets.

@vpascual
Last active February 28, 2018 16:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vpascual/33c26d3b87c6d96d1606ed811d906804 to your computer and use it in GitHub Desktop.
Save vpascual/33c26d3b87c6d96d1606ed811d906804 to your computer and use it in GitHub Desktop.
D3 basic barchart with divs
license: mit
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>D3 Page Template</title>
<script src="https://d3js.org/d3.v4.min.js"></script>
</head>
<body>
<script type="text/javascript">
// D3 code
const data = [18, 20, 25, 34, 100];
var scale = d3.scaleLinear()
.domain([0, d3.max(data)])
.range([0, 400]);
d3.select("body")
.selectAll("div")
.data(data)
.enter()
.append("div")
.style("width", (d) => { return scale(d) + "px"; })
.style("background-color", "steelblue")
.text((d) => { return d; })
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment