Skip to content

Instantly share code, notes, and snippets.

@devgru
Last active October 5, 2016 14:38
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 devgru/10524216 to your computer and use it in GitHub Desktop.
Save devgru/10524216 to your computer and use it in GitHub Desktop.
Heatmap — basic
license: mit
<html>
<body>
<script type='text/javascript' src='http://d3js.org/d3.v4.min.js'></script>
<script>
var url = "https://api.github.com/repos/mbostock/d3/stats/punch_card"
var color = d3.scaleLinear().range(['white', 'blue'])
d3.json(url, function (data) {
color.domain(d3.extent(data, function (d) { return d[2] }))
d3.select('body')
.append('svg')
.selectAll('rect')
.data(data)
.enter()
.append('rect')
.attr('x', function (d) { return d[1] * 20 })
.attr('y', function (d) { return d[0] * 20 })
.attr('width', 20)
.attr('height', 20)
.style('fill', function (d) { return color(d[2]) })
})
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment