我正在使用 D3 绘制一些数据图表,如果我将我的时区更改为远离当前时区,时间尺度会根据我客户的时区而变化。我宁愿能够强制图表在一个时区显示,因为这是在查看数据时有意义的内容。
我正在使用
x.domain([lowerTime, upperTime])
创建 x 轴,但我不确定如何利用
x.timeFormat()
要强制这个域在某个时区,有人可以帮忙吗?
最佳答案
通过使用 Time Scales您可以获得以下内容:
# d3.time.scale.utc()
Constructs a new time scale with the default domain and range; the ticks and tick format are configured for UTC time.
所以,最后你可以这样做:
scale = d3.time.scale.utc()
scale.domain([lowerTime, upperTime])
现在您在任何客户端上都有相同的时间。您仍然需要弄清楚您当前的 UTC 时间是多少,但这要容易得多。
关于javascript - d3 图有客户的时区而不是数据的,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15957466/