javascript 如何使用间隔和日期开始将日期时间分配给 highchart
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/16940512/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
how to assign date time to highchart with intervals and date start
提问by agarwal_achhnera
HI In highchart is there any way to give time on x-axis as below
HI 在 highchart 中,有什么方法可以在 x 轴上给出时间,如下所示
1) pass start time
2) give an array of time points
3) give unit of time
1) 传递开始时间
2) 给出时间点数组
3) 给出时间单位
for example
例如
start time will set as pointStart: Date.UTC(timeArr[3],timeArr[1],timeArr[2],timeArr[4],timeArr[5]) where timeArr[3] -> year timeArr[3] -> year timeArr[1] -> month timeArr[2] -> day of month timeArr[4] -> hour timeArr[5] -> minute now set time intervals array as below [0,60,120,180,240] now give unit of time as 1000(which tells time in array is in seconds)
And then highchart plot the x-axis by starting from start date and then pick interval from time array and add to start time and create time for next datapoint
然后 highchart 从开始日期开始绘制 x 轴,然后从时间数组中选择间隔并添加到开始时间并为下一个数据点创建时间
I ask this question because our old application uses JClass chart and I am converting from that and that works on the logic I give
我问这个问题是因为我们的旧应用程序使用 JClass 图表,我正在从中进行转换,这适用于我给出的逻辑
回答by Pablo Pazos
Set the initial date with pointStart:
使用 pointStart 设置初始日期:
plotOptions: {
column: {
pointStart: Date.UTC(2015, 1, 12) // feb 12, 2015
}
}
Set the interval in the xAxis:
在 xAxis 中设置间隔:
xAxis: {
type: 'datetime',
dateTimeLabelFormats: {
second: '%H:%M:%S',
minute: '%H:%M',
hour: '%H:%M',
day: '%e. %b',
week: '%e. %b',
month: '%b \'%y',
year: '%Y'
},
tickInterval: 24 * 3600 * 1000 // interval of 1 day (in your case = 60)
}
回答by jlbriggs
If I understand correctly, pointInterval is what you are looking for:
如果我理解正确, pointInterval 就是你要找的:
http://api.highcharts.com/highcharts#plotOptions.series.pointInterval
http://api.highcharts.com/highcharts#plotOptions.series.pointInterval
If that doesn't do what you need, then it should just be a matter of parsing your object to get it do what you need...
如果这不能满足您的需求,那么只需解析您的对象以使其满足您的需求...