代码之家  ›  专栏  ›  技术社区  ›  TheDoctor

d3js缩放/轴通过(用户)选择获取刻度

  •  0
  • TheDoctor  · 技术社区  · 6 年前

    我通过 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)");
    

    给了我这个 xAxis : enter image description here

    现在我需要从轴上选择一个(子)时间范围,类似于: enter image description here

    我怎样才能做到这一点?

    0 回复  |  直到 6 年前