Skip to content

Instantly share code, notes, and snippets.

@bgorkem
Last active October 17, 2019 17:01
Show Gist options
  • Save bgorkem/7836b86822be9620a4c6e7baff6f7f4f to your computer and use it in GitHub Desktop.
Save bgorkem/7836b86822be9620a4c6e7baff6f7f4f to your computer and use it in GitHub Desktop.
rectangle bar chart intro
license: mit
<!DOCTYPE html>
<head>
<meta charset="utf-8">
<script src="https://d3js.org/d3.v4.min.js"></script>
</head>
<body>
<svg height="420" width="530" style="border:solid 1px gray;">
</svg>
<script>
var data = [100,200,300,30,40]
var rectWidth = 100;
d3.select('svg').selectAll('rect')
.data(data)
.enter().append('rect')
.attr('x', (d,i)=> (i*rectWidth)+5 )
.attr('y', d=> 400-d)
.attr('width',rectWidth-5)
.attr('height',d=>d)
.attr('fill','orange')
.attr('stroke','black')
.attr('stroke-width',2)
console.log('d3 sel', d3.selectAll('rect'))
</script>
</body>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment