Created
November 20, 2017 20:56
-
-
Save bmorelli25/bb496535badb93fc1f98478020cb6965 to your computer and use it in GitHub Desktop.
D3 Bar Chart
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
| const w = 400, h = 250; | |
| const padding = 4; | |
| const data = [50,100,150,200,250,130,210,30,170]; | |
| let svg = d3.select('body') | |
| .append('svg') | |
| .attr('width', w) | |
| .attr('height', h); | |
| svg.selectAll('rect') | |
| .data(data) | |
| .enter() | |
| .append('rect') | |
| .attrs({ | |
| x: (d, i) => i * (w / data.length), | |
| y: d => h - d, | |
| width: w / data.length - padding, | |
| height: d => d, | |
| fill: 'green' | |
| }); | |
| svg.selectAll('text') | |
| .data(data) | |
| .enter() | |
| .append('text') | |
| .text((d) => d) | |
| .attrs({ | |
| x: (d,i) => i * (w / data.length) + (w / data.length - padding) / 2, | |
| y: (d) => h - d + 20 | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment