使用Highcharts在yAxis上绘制秒,分钟和小时 [英] Plotting seconds, minutes and hours on the yAxis with Highcharts

查看:78
本文介绍了使用Highcharts在yAxis上绘制秒,分钟和小时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一些如下所示的数据:


min =00:09med =03:11mean = 23:39max =12:40:26


我希望能够使用这些值作为数据点,但我不知道如何绘制它们,因为它们不是简单的整数。理想情况下,我希望Y轴上的标签显示'小时',或者如果我要使用多个y轴,则可以显示'最小'值为'秒','平均'显示'分钟'值等等,以适应适当的时间窗口。



我不确定我是否可以使用日期时间对象,因为我只有时间值而不是日期。 / p>

如果您有任何想法,请事先了解并提前致谢。

你有时间是静态字符串,你可以将它们转换为日期时间对象...

  // convert'string'时间转换为时间戳(毫秒)
//只要字符串时间格式一致
//例如0:03:00不是3:00
var t = Date.parse(1-1-1+ yourTime)

...但是如果你可以把它们变成毫秒级的数值​​,你应该没问题。

然后,

然后为y轴使用正常时间格式,并使用日期标签格式按照您的喜好进行格式化...

  var chart = new HighChart({
// ...
yAxis:{
type:'datetime',// y轴将以毫秒为单位
dateTimeLabelFormats:{// force所有格式为小时:分钟:秒钟
秒:'%H:%M:%S',
分钟:'%H:%M:%S',
小时:'' %H:%M:%S',
日:'%H:%M:%S',
星期:'%H:%M:%S',
月份: '%H:%M:%S',
年:'%H:%M:%S'
}
}
});


I have some data that looks like this:

min="00:09" med="03:11" mean="23:39" max="12:40:26"

I'd like to be able to be able to use these values as datapoints but I'm not sure how to plot them as they are not simple integers. Ideally I'd like to have the labels on the Y axis show something like 'hours' or if I was to use multiple y axes then it could show 'seconds' for the 'min' values, 'minutes' for the 'mean' values and so on adapting to the appropriate time window.

I'm not sure if I can use datetime objects as I only have a time value and not a date.

Any ideas will be appreciated and thanks in advance.

解决方案

If the times that you have are static strings, you can convert them into a datetime object...

//convert 'string' times into a timestamp (milliseconds)
//so long as your string times are consistently formatted
//e.g. "0:03:00" not "3:00"
var t = Date.parse("1-1-1 " + yourTime)

...But if you can turn them into a millisecond value at all, you should be fine.

Then use normal time format for the y-axis, and format it as you like using the date label format...

var chart = new HighChart({
    //...
    yAxis: {
        type: 'datetime', //y-axis will be in milliseconds
        dateTimeLabelFormats: { //force all formats to be hour:minute:second
            second: '%H:%M:%S',
            minute: '%H:%M:%S',
            hour: '%H:%M:%S',
            day: '%H:%M:%S',
            week: '%H:%M:%S',
            month: '%H:%M:%S',
            year: '%H:%M:%S'
        }
    }
});

这篇关于使用Highcharts在yAxis上绘制秒,分钟和小时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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