rickshaw: Timezone is not adjustable for Time based axis

While very elegant, the existing system doesn’t seem to allow displaying the x axis unix timestamps using whatever time zone is appropriate (browser time zone for example).

It ends up using (for hour formatting) something like this:

new Date(1350425400*1000).toUTCString().match(/(\d+:\d+):/)[1]

no matter what

About this issue

  • Original URL
  • State: open
  • Created 12 years ago
  • Comments: 27 (6 by maintainers)

Most upvoted comments

The Rickshaw documentation is really bad, so you have to read the source code to make sense of the library which is agony for new comers. Maybe we all should make a public documentation for this amazing library.

Anyway, here’s a simple solution.

For the X-Axis use - Rickshaw.Fixtures.Time.Local():

var x_axis = new Rickshaw.Graph.Axis.Time( {
            graph: graph,
            timeFixture: new Rickshaw.Fixtures.Time.Local()
        } );

Now you might have face inconsistency with Rickshaw.Graph.HoverDetail. So for that, update the xFormatter as follows:

var hoverDetail = new Rickshaw.Graph.HoverDetail( {
        graph: graph,
        xFormatter: function(x) {
                return new Date( x * 1000 ).toLocaleString();
                    }
        });

This is because Rickshaw by default uses toUTCString(). You can further modify the date format to your liking.

Side note: Rickshaw uses seconds instead of milliseconds, therefore the (x * 1000)