我正在研究MEAN应用程序。我正在尝试在Y轴上显示一些值,并在X轴上显示日期时间,时间间隔为3小时(即12 AM,3 AM,6 AM,9 AM,12 PM,3 PM .....
我的Y轴代码是这样的。
yaxis: {
tickmode:"array",
tickvals:[0,0.5,1.5,4,8,16],
ticktext:[0,0.5,1.5,4,8,16],
showgrid: false,
showline: true,
autoscale: true,
autorange: true,
fixedrange: true,
ticks: 'outside',
zeroline: false
},
xaxis: {
showgrid: false,
showline: true,
ticks: 'outside',
zeroline: false
}
有人可以帮我吗?预先感谢。
答案 0 :(得分:0)
您可以创建一个datetime
间隔为3h
的值的xaxis
数组。
//make a date-time array with a interval
function makeRange(y,interval) {
//y is yaxis data
//interval is a numeric value for hour
var x = []; //date array
var d = new Date();
for(i=0; i<y.length; i++){
d.setHours(i*interval,0,0) //Add hour interval in date time
var hours = d.getHours(); //get hours
var ampm = hours >= 12 ? 'PM' : 'AM'; //set am/pm
var date = d.getDate() + "-" + (d.getMonth()+1) + "-" + d.getFullYear() + " " + hours + ":" + d.getMinutes() + ampm; //create date format
x.push(date)
}
return x;
}