使x轴和刻度在d3中消失

时间:2018-10-10 09:08:42

标签: d3.js visualization

我想只使x轴标签消失。目前,我有以下代码,但是它使整个x轴消失了,我想保持水平线。

有没有一种方法可以只针对刻度和文本?

// Make x-axis
let xAxis = d3.axisBottom(scaleX);
svg.append("g")
  .attr("class", "axis")
  .attr("transform", "translate(0," + height + ")")
  .attr("opacity", 0.7)
  .call(xAxis);

// Target x-axis; but this targets the entire axis
let setXAxisOpacity = (opacity, duration=120) => {
    d3.select(".axis")
     .transition()
     .duration(duration)
     .ease(d3.easeLinear)
     .style("opacity", opacity)
}

1 个答案:

答案 0 :(得分:1)

您需要定位轴的textline部分

d3.select('.axis').selectAll('text')
     .transition()
     .duration(duration)
     .ease(d3.easeLinear)
     .style("opacity", opacity);
d3.select('.axis').selectAll('line')
     .transition()
     .duration(duration)
     .ease(d3.easeLinear)
     .style("opacity", opacity);