【问题标题】:NVD3 x-axis labels misaligned for lineChart and historicalChartNVD3 x 轴标签未对齐 lineChart 和historyChart
【发布时间】:2017-07-03 07:54:13
【问题描述】:

这类似于here 报告的问题。

在这个工作example 的示例中,我实现了一个折线图和一个历史图表。

chart.xAxis
    .showMaxMin(true)
    .tickFormat(function(d) { return d3.time.format('%b %d')(new Date(d)) })

一切都按预期工作,除了 x 轴中的轴标签与线点或条不同步。

正如this issue 中建议的解决方案所说,这是由于日期格式问题,我尝试在new example 中设置日期/时间格式。 但问题依旧。

chart.xAxis
    .showMaxMin(true)
    .tickFormat(function(d) { return d3.time.format('%b %d %Y')(new Date(d)) })

对我来说,它最初看起来是 NVD3 库的问题,因为相同的格式对于我检查的其他图表类型非常有效。因此我提出了一个问题here

【问题讨论】:

    标签: d3.js charts nvd3.js linechart


    【解决方案1】:

    您需要设置 xScale。做chart.xScale(d3.time.scale())

    【讨论】:

    • 谢谢。这是完美的。
    猜你喜欢
    • 1970-01-01
    • 2014-08-28
    • 1970-01-01
    • 1970-01-01
    • 2019-07-12
    • 2013-07-27
    • 1970-01-01
    • 1970-01-01
    • 2014-09-07
    相关资源
    最近更新 更多