我通过d3js v5
创建了一个时间刻度:
let domain = ["1989-02-03T23:00:00.000Z","1989-02-03T23:00:00.000Z",
"2012-12-11T23:00:00.000Z","2013-04-11T22:00:00.000Z",
"1941-04-11T22:00:00.000Z","1940-03-31T23:00:00.000Z",
"2040-04-18T22:00:00.000Z"];
let x = d3.scaleLinear().domain([minDate, maxDate]).range([0, verticalWidth]);
let xAxis = d3.axisBottom(x).tickFormat(d3.timeFormat("%Y-%M-%d")).tickValues(domain);
// TODO fix if ticks/dates to close to each other ( => overlapping)
horizontalTreeSVG.append('g').attr("id", "xAxis")
.call(xAxis)
.selectAll("text")
.style("text-anchor", "end")
.attr("dx", "-.8em")
.attr("dy", ".15em")
.attr("transform", "rotate(-65)");
现在我需要从轴中选择一个(sub)时间范围,有点像: 并获得此选择中的刻度/日期。
我该怎么做?