Created
August 8, 2019 21:20
-
-
Save connerxyz/fc6bc23b2678f26bed64cd38011609ac to your computer and use it in GitHub Desktop.
d3.js: v5: scaling number of ticks with window's inner width
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
var xScale = d3.scaleTime() | |
.domain(d3.extent(data, function(d) { return d.key; })) // Input | |
.range([0, width]); // output | |
// Quantize 400px - 1600px window range | |
var tickScale = d3.scaleQuantize() | |
.domain([400, 1600]) | |
.range([3, 7, 10]); | |
// Set number of ticks based on window height | |
svg.append("g") | |
.attr("class", "x axis") | |
.attr("transform", "translate(0," + height + ")") | |
.call(d3.axisBottom(xScale).ticks(tickScale(window.innerWidth))); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment