d3 graph has client's time zone instead of data's
Asked Answered
B

2

7

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?

Bally answered 11/4, 2013 at 19:41 Comment(1)
What format are the dates in your data in?Wayfaring
B
2

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.

Boyes answered 12/4, 2013 at 7:6 Comment(0)
B
0

You can use UTC, or format the tick labels to use a specific timezone

Blunger answered 6/1, 2017 at 15:44 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.