2

I have added a datetime X-axis to my rickshaw graph:

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

However, it doesn't generally give me the format I want. Can I give it a specifier so the datetimes are always in a specified format (i.e. something like d3.time.format(specifier) )?

Kyle Brandt
  • 26,938
  • 37
  • 124
  • 165

3 Answers3

2

Based on Lars' linked example I have done the following:

var format = function(d) {
    d = new Date(d)
    return d3.time.format("%c")(d)
}
var x_axis = new Rickshaw.Graph.Axis.X({
        graph: graph,
        tickFormat: format,
});

Which seems to work, so now I just have to find a way to make the spacing come out okay....

Kyle Brandt
  • 26,938
  • 37
  • 124
  • 165
1

The formatter will only format the string, it will not determine the spacing. In order to control spacing and formatting, you could write your own 'Fixture', e.g. take a look at https://github.com/shutterstock/rickshaw/blob/master/src/js/Rickshaw.Fixtures.Time.js for an example. The fixture provides two things: the spacing (e.g. year, month, day, hour) and the formatting of each. Create a similar fixture, space and format to your needs and set it on the x-axis:

var xAxis = new Rickshaw.Graph.Axis.Time( {
  graph: graph,
  //timeFixture: new Rickshaw.Fixtures.Time()
  timeFixture: new MyOwnTimeFixture()
} );
BjrnSmn
  • 376
  • 3
  • 8
1

try this one it will work

var xAxis = new Rickshaw.Graph.Axis.Time({
        graph: graph,
        tickFormat: function(x){
            return new Date(x).toLocaleString();
        },
        ticks: 4
    });
Deepak Sharma
  • 458
  • 9
  • 21