D3.js line chart: axis with fixed position

后端 未结 2 1665
北海茫月
北海茫月 2021-01-28 11:17

i got a normal line chart written in d3.js

body {
    font: 10px sans-serif;
}

.axis path,
.axis line {
    fill: none;
    stroke: #000;
    shape-rendering: c         


        
相关标签:
2条回答
  • 2021-01-28 11:22

    Try applying the style when you generate the axis.

    svg.append("g")
            .attr("class", "x axis")
            .attr("transform", "translate(0," + height + ")")
            .style("position", "fixed")
            .call(xAxis);
    
    0 讨论(0)
  • 2021-01-28 11:28
    window.onscroll = function() {myFunction()};
    
            function myFunction() {
                if(window.pageYOffset == 0)
                {
                    d3.select("#test").nodes()[0].setAttribute("transform", "translate(200, " + 10  +")")
                }
                 if (window.pageYOffset > 0) {
                  d3.select("#test").nodes()[0].setAttribute("transform", "translate(200, " + window.pageYOffset  +")")
    }
    }
    
    0 讨论(0)
提交回复
热议问题