以固定间隔在x轴上渲染Highcharts数据时间 [英] rendering Highcharts datatimes on the x axis at regular intervals
问题描述
我有两个充满数据的数组。一个数组只是随机整数(例如1.7,2.8,3.4等),另一个数组是该数据的相应时间戳的对应列表(例如1366585199)。
I have two arrays full of data. One array is just random integers (e.g. 1.7, 2.8, 3.4, etc.) and the other array is a corresponding list of unix timestamps for that data, (e.g. 1366585199).
目前,我的Highcharts代码看起来像这样:
At the moment my Highcharts code looks a little something like this:
dataArray = ("2.4","5.6","3.1", ...);
timeArray = ("1366585199","1366585233","1366585355", ...)
function foo(dataArray, timeArray) {
$('#viz_1').highcharts({
chart: {
type: 'line'
},
title: {
text: 'Data Index'
},
xAxis: {
type: 'datetime', // this isn't doing anything??
categories: timeArray
},
yAxis: {
title: {
text: 'Data Value'
},
},
series: [{
name: topicID,
data: JSON.parse("[" + dataArray + "]")
}]
})
};
这适用于向页面呈现折线图,但X轴明显充满了大约50个Unix时间戳!
This works and renders a line graph to the page but the X Axis is obviously full of about 50 Unix timestamps!
我似乎无法弄清楚如何让Highcharts API获取Unix时间戳数组,用它来排列数据点,但只显示一个X轴上的人类可读日期是否定期?
I can't seem to figure out how to get the Highcharts API to take the array of Unix timestamps, use it to line up the data points, but only show a human-readable date on the X axis at regular intervals?
推荐答案
你不能混合'datetime'
和类别
。
我倾向于将x / y值作为成对发送到HighCharts。喜欢:
You cannot mix 'datetime'
and categories
.
It is my preference to send in the x/y values as pairs into HighCharts. Like:
data: [
[Date.parse('01/01/2000 00:00:00'), 55205],
[Date.parse('01/01/2003 00:00:00'), 59091],
[Date.parse('01/01/2004 00:00:00'), 64347],
[Date.parse('01/01/2005 00:00:00'), 71067],
[Date.parse('01/01/2006 00:00:00'), 77770],
[Date.parse('01/01/2011 00:00:00'), 81166]
]
如果您有javascript时间戳,您也可以发送以下内容:
If you have javascript timestamps you can send those in as well like:
[31536000000, 456]
这篇关于以固定间隔在x轴上渲染Highcharts数据时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!