【问题标题】:D3 rendering xAxis Months differently between FF and ChromeD3 在 FF 和 Chrome 之间呈现不同的 xAxis Months
【发布时间】:2017-12-20 21:12:42
【问题描述】:

我创建了一个简单的条形图,其中 yAxis 是任意编号,xAxis 是从 1 月 17 日到 1 月 18 日的时间刻度。出于某种奇怪的原因,Chrome 没有显示第一个月(1 月 17 日)。对于 Firefox,我有预期的结果。

我尝试使用 [utcMonth || 的组合。 timeMonth] 和 [utcFormat || monthFormat]。每个都有不同的结果。

我是否想念 chrome 和 firefox 之间的理解?

JS

  x = d3.scaleTime()
        .domain([new Date("2017-1-1"), new Date("2018-1-1")])
        .range([0, this.width - this.margin.left - this.margin.right - 40]);

  drawXAxis() {
   this.xAxis = this.g.append("g")
    .classed("bar-x-axis", true)
    .call(d3.axisBottom(this.x)
      .ticks(d3.utcMonth.every(1))
      .tickFormat(d3.utcFormat("%b-%y"))
  );
 }

CSS

.bar-x-axis text{
  text-anchor: middle;
}

.bar-x-axis path {
  display: none;
}

附件是两个浏览器的例子 注意:Chrome 不显示 Jan17

chrome ff

【问题讨论】:

    标签: javascript reactjs d3.js


    【解决方案1】:

    没关系,我认为这可能是一个潜在的错误

    通过将 new Date("2017-1-1") 更改为 new Date(2017, 0, 1) 来修复它

    【讨论】:

      猜你喜欢
      • 2014-06-22
      • 2015-04-27
      • 2012-09-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-01-14
      • 1970-01-01
      相关资源
      最近更新 更多