Built with blockbuilder.org
Last active
October 17, 2019 17:01
-
-
Save bgorkem/7836b86822be9620a4c6e7baff6f7f4f to your computer and use it in GitHub Desktop.
rectangle bar chart intro
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
license: mit |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!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