-
-
Save nick3499/9568ab3f0e9dbff1078d0f3b84ff392c to your computer and use it in GitHub Desktop.
D3byEX 4.6: Top Axis (Adapted to D3.js v4)
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> | |
| <meta charset=utf-8> | |
| <head> | |
| <script src="http://d3js.org/d3.v4.min.js"></script> | |
| <script src="https://d3js.org/d3-selection-multi.v1.min.js"></script> | |
| <meta name="description" | |
| content="D3.js v4, .scaleLinear, .axisTop, axis top" /> | |
| </head> | |
| <body> | |
| <script> | |
| var data = [55, 44, 30, 23, 17, 14, 16, 25, 41, 61, 85, 101, 95, 105, | |
| 114, 150, 180, 210, 125, 100, 71, 75, 72, 67]; | |
| var maxValue = d3.max(data); | |
| var width = 500, height = 500; | |
| var svg = d3.select("body") | |
| .append("svg") | |
| .attrs({width: width, height: height}); // selection multi | |
| var scale = d3.scaleLinear() // v4 | |
| .domain([0, maxValue]) | |
| .range([0, width]); // clipped | |
| var axisGroup = svg.append("g") | |
| .attr("transform", "translate(0,50)"); | |
| var axis = d3.axisTop() // v4 | |
| .scale(scale) | |
| .tickSize(10) // added | |
| .tickPadding(6); // added | |
| var axisNodes = axisGroup.call(axis); | |
| </script> | |
| </body> | |
| </html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment