Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Nvd3 chart different time zone

I'm struggling now with a time problem.

I'm using the NVD3 library to create my chart, I calculate all the chart data at the server side.

The problem is that the time range at the graph is according to my computer time (GMT+3) and not my machine (UTC). How can I fetch it to be UTC and not GMT+3?

What can I do?

I'm adding my code if it can help

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;
like image 822
lobliba Avatar asked May 20 '26 04:05

lobliba


1 Answers

found a solution !

 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) )) }
});
like image 137
lobliba Avatar answered May 22 '26 16:05

lobliba



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!