I am creating a timeline visualization with d3 where the domain can vary from a few days to several decades. I use the d3 timeline and axis like this:
var timeScale = d3.time.scale() .domain([firstEvent, lastEvent]) .range([leftPadding, w - rightPadding]); var timeAxis = d3.svg.axis() .scale(timeScale) .orient("bottom"); timeAxis.ticks(5);
Since the domain is so variable, itβs convenient to use ticks(x) , which automatically selects the tick format. My problem is that in some cases the year is not shown, which is crucial. My idea was to check the tick format after creating the axis, and if it does not contain a year, show it manually next to the axis. However, I could not get the scale format of the scale; using timeScale.tickFormat() just returns a function. How can I solve this problem?
source share