gpt4 book ai didi

javascript - 在 d3.scaleTime() 中获取恒定的刻度间隔值

转载 作者:行者123 更新时间:2023-11-28 04:52:01 24 4
gpt4 key购买 nike

DEMO

我需要使用d3.scaleTime()在任何随机日期之间获取恒定的刻度值间隔并在轴上绘制。

但是

timeScale.nice(intervalValue);
//or
axisXScale.tickValues(timeScale.ticks(10));

没有帮助,我总是得到随机数量的刻度值。

根据 D3 文档

# continuous.ticks([count])

Returns approximately count representative values from the scale’s domain. If count is not specified, it defaults to 10.
The returned tick values are uniformly spaced, have human-readable values (such as multiples of powers of 10), and are guaranteed to be within the extent of the domain.
Ticks are often used to display reference lines, or tick marks, in conjunction with the visualized data.
The specified count is only a hint; the scale may return more or fewer values depending on the domain.

有什么方法可以得到一个常数而不是近似值

最佳答案

我认为你需要做这样的事情:

.ticks(d3.timeMonth.every(1))

欲了解更多详情,请访问http://www.d3noob.org/2016/08/changing-number-of-ticks-on-axis-in.html .

希望这有帮助!

关于javascript - 在 d3.scaleTime() 中获取恒定的刻度间隔值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42838389/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com