Last active
November 17, 2015 18:43
-
-
Save d3byex/ee3e4273cea58aac5718 to your computer and use it in GitHub Desktop.
D3byJS 4.1: Basic 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
| <!DOCTYPE html> | |
| <html> | |
| <head> | |
| <script src="http://d3js.org/d3.v3.min.js"></script> | |
| <meta name="description" content="D3byEX 4.1" /> | |
| <meta charset="utf-8"> | |
| </head> | |
| <body> | |
| <script> | |
| var data = [55, 44, 30, 23, 17, 14, 16, 25, 41, 61, 85, | |
| 101, 95, 105, 114, 123, 123, 111, 91, 75, 71, | |
| 75, 72, 67]; | |
| var barWidth = 20, barPadding = 3; | |
| var maxValue = d3.max(data); | |
| var g = d3.select('body') | |
| .append('svg') | |
| .attr({ width: 1000, height: 250 }) | |
| .append('g'); | |
| function xloc(d, i) { return i * (barWidth + barPadding); } | |
| function yloc(d) { return maxValue - d; } | |
| function translator(d, i) { | |
| return "translate(" + xloc(d, i) + "," + yloc(d) + ")"; | |
| } | |
| g.selectAll("rect") | |
| .data(data) | |
| .enter() | |
| .append('rect') | |
| .attr({ | |
| fill: 'steelblue', | |
| transform: translator, | |
| width: barWidth, | |
| height: function (d) { return d; } | |
| }); | |
| </script> | |
| </body> | |
| </html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment