Flotr x轴日期/时间
问题描述:
我在我的应用程式中使用 flotr ,我需要一些简单的方法在x轴上显示日期。我知道flotr能够通过
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}
但是日期怎么样?无论如何,我不能得到时间x轴工作,所以任何真正的时间x轴的例子也将赞赏。
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.
答
只需将您的数据添加为[timestamp,value],时间戳以毫秒为单位。
然后使用选项'tickFormatter'来实现你自己的格式化函数。
Simply add your data as [ timestamp , value ], timestamp being in ms. Then use the option 'tickFormatter' to implement your own formatting function.
首先实现你的formating函数:
First implement your formating function:
function myDateFormater(inputTimeStamp) {
mydate = new Date();
mydate.setTime(inputTimeStamp);
// Return your formated date as you like.
return formatedDate ..
}
然后将此函数设置为
xaxis: {
...
tickFormatter: myDateFormater, // => fn: number -> string
...
}