views:

815

answers:

1

I'm using flotr in my app and I need some simple way to show dates on x-axis. I know flotr is able to display time on x-axis via

'xaxis' : {'mode' : 'time', 'min' => '??', 'max' => '??', 'timeFormat' => '??', 'noTicks' => 10}

But how about dates? Anyhow, I can't get time x-axis working either, so any real example of time x-axis would be appreciated too.

+2  A: 

Simply add your data as [ timestamp , value ], timestamp being in ms. Then use the option 'tickFormatter' to implement your own formatting function.

First implement your formating function:

function myDateFormater(inputTimeStamp) {
mydate = new Date();
mydate.setTime(inputTimeStamp);
// Return your formated date as you like.
return formatedDate ..
}

Then set this function as a formater for the x-axis ticks.

xaxis: {
  ...
  tickFormatter: myDateFormater, // => fn: number -> string
  ...
}
jeje
Oh man! It was so obvious! In the end I used another approach, but mostly based on your suggestion. Thank you.
picca