Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

d3 graph has client's time zone instead of data's

I'm using D3 to graph some data, and if I change my time zone away from my current one, the time scale changes based on my client's time zone. I would rather be able to force the graph to display in one time zone because that's what the data makes sense when being looked at.

I am using

x.domain([lowerTime, upperTime]) 

to create the x axis, but I'm not sure how I'd take advantage of

x.timeFormat()

to force this domain to be in a certain time zone, can anyone help here?

like image 279
cdietschrun Avatar asked Apr 11 '13 19:04

cdietschrun


1 Answers

By using Time Scales you can get the following:

# 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.

So, in the end you can do:

scale = d3.time.scale.utc()
scale.domain([lowerTime, upperTime])

Now you have the same time on any client. You still have to figure out what is your current time in UTC, but it is way easier.

like image 124
Christopher Chiche Avatar answered Nov 07 '22 09:11

Christopher Chiche