Chart d3 has client time zone, not data

I use D3 to graphically display some data, and if I change my time zone away from my current, the time scale based on my client’s time zone will change. I would rather get the chart to display in the same time zone, because this is what the data makes sense when viewing.

I use

x.domain([lowerTime, upperTime]) 

to create the x axis, but I'm not sure how I will use it

 x.timeFormat() 

to make this domain be in a specific time zone, can anyone help here?

+4
source share
2 answers

Using Time Scales , you can get the following:

# d3.time.scale.utc ()

Creates a new timeline with a default domain and range; ticks and tick format are configured for UTC.

So at 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 your current time is in UTC, but it is much simpler.

+2
source

You can use UTC or format tick shortcuts to use a specific time zone.

0
source

All Articles