【问题标题】:D3: How to remove tick marks at the top and bottom of Y axisD3:如何去除 Y 轴顶部和底部的刻度线
【发布时间】:2018-02-04 02:08:55
【问题描述】:

我不知道如何关闭 D3 图表中 y 轴顶部和底部的这些刻度线。任何帮助将不胜感激!

这是我生成轴的方式:

// Set the ranges
var xScale = d3.time.scale().range([0, width]);
var yScale = d3.scale.linear().range([height, 0]);

// Define the axes
var xAxis = d3.svg.axis().scale(xScale)
  .orient("bottom")
  .ticks(2)
  .tickFormat(formatTime);

var yAxis = d3.svg.axis().scale(yScale)
  .orient("left")
  .ticks(2)
  .tickFormat(d3.format("$,"));

【问题讨论】:

  • 如果您不共享代码,将很难提供帮助。
  • 在你的轴生成器中,把这个(如果是 v4.x):.tickSizeOuter(0).
  • Gerardo,我尝试添加该函数,但显然做错了什么: var yAxis = d3.svg.axis() .tickSizeOuter(0) .scale(yScale) .orient("left" ) .ticks(2) .tickFormat(d3.format("$,"));``` 我得到错误... tickSizeOuter is not a function...
  • 因为您使用的是 v3。我在评论中写了 v4
  • 在 v3 中是 .outerTickSize(0)。自从我上次使用 v3 以来已经很长时间了,我不得不搜索 API 才能记住它。

标签: javascript d3.js data-visualization


【解决方案1】:

更好地使用 CSS

.y.axis .tick line:first-child, 
.y.axis .tick line:last-child{
   opacity: 0;
}

【讨论】:

    【解决方案2】:

    您可以使用此脚本删除 y 轴上的所有刻度。

    d3.selectAll(".y.axis").selectAll(".tick").selectAll("line").remove();
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-12-22
      • 2018-08-03
      • 1970-01-01
      • 2015-05-11
      • 1970-01-01
      • 2021-02-06
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多