我现在正在为时间问题而苦苦挣扎。
我正在使用 NVD3 库 创建我的图表,我在服务器端 计算所有图表数据。
问题是图表中的时间范围是根据我的计算机时间 (GMT+3) 而不是不是我的机器 (UTC)。我怎样才能将其获取为 UTC 而不是 GMT+3?
我能做什么?
如果有帮助,我会添加我的代码
nv.addGraph(function() {
var chart = nv.models.lineWithFocusChart().x(function(d) {return d[0];}).y(function(d) { return d[1]; });
chart.yAxis
.tickFormat(d3.format(',.2f'));
chart.y2Axis
.tickFormat(d3.format(',.2f'));
chart.xAxis
.tickFormat(function(d) { return d3.time.format('%H:%M:%Z')(new Date(d)) });
chart.x2Axis
.tickFormat(function(d) { return d3.time.format('%H:%M:%Z')(new Date(d)) });
d3.select('#chart svg')
.datum(data)
.transition().duration(500)
.call(chart);
return chart;
最佳答案
找到了解决方案!
var now =new Date();
chart.xAxis.tickFormat(function(d) { if (d!= undefined)
{
return d3.time.format('%H:%M')(new Date(d+ now.getTimezoneOffset() * 60000 +Number(timeZoneOffset) )) }
});
关于javascript - Nvd3图表不同时区,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38040304/