在 jQuery flot 中在 y 轴上显示小时
我制作了一个图表,在 y 轴上显示小时。但现在我必须将时间转换为小数。
2:30 将是 2.5
我知道你可以将 y 轴设置为时间模式,但我可以无法让它工作:
yaxis: {
mode: "time",
timeformat: "%H:%M"
},
但是我应该如何将小时数传递给 jQuery Plot:“1:40”不起作用
我想让它看起来像这样,只需要几个小时而不是几分钟
我在互联网上搜索帮助,jQuery API 没有正确解释它: http://flot.googlecode.com/svn/trunk/API.txt
非常感谢您的帮助!
I have made a chart where i show hours on y axis. But now i have to convert the time to a decimal.
2:30 would be 2.5
I know that you can set y axis to time mode, but I can not get it to work:
yaxis: {
mode: "time",
timeformat: "%H:%M"
},
But how should i deliver the hours to jQuery Plot: "1:40" do not work
I would like to make it look this way with just hours instead of minutes
I have search the internet for help and the jQuery API do not explain it properly:
http://flot.googlecode.com/svn/trunk/API.txt
Thank you very much for your help!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您想要做的只是使用轴 tickFormatter 来伪造它。 “时间”模式实际上应该被称为“日期”模式,因为它是关于日期而不是时间。时间真的只是偶然。因此,如果您已经完成了将时间转换为十进制的工作,只需使用 JavaScript 函数将它们转换回您想要的格式:
这显然并没有涵盖所有排列(即,如果您需要的话,可以在前导零) ,但这就是想法。如果您不知道如何将其放入 flot 中,请在绘图选项中如下所示:
What you want to do is just fake it up using the axis tickFormatter. The "time" mode should really be called something like "date" mode, because it's about dates not times. The time is just incidental really. So if you're already doing the work to convert the times to a decimal, just use a javascript function to convert them back to the format you want:
That doesn't cover all the permutations obviously (i.e. leading zeros if you want them), but that's the idea. If you don't know how to put this into flot, it's like this in your plot options: