Flotr x 轴日期/时间 [英] Flotr x-axis date/time

查看:23
本文介绍了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.

首先实现你的格式化功能:

First implement your formating function:

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

然后将此函数设置为 x 轴刻度的格式器.

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

xaxis: {
  ...
  tickFormatter: myDateFormater, // => fn: number -> string
  ...
}

这篇关于Flotr x 轴日期/时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆